Home > database >  Add csv import data to mysql db
Add csv import data to mysql db

Time:05-20

Good morning, I created a script in php to import a csv file into the mysql table and so far no problem.

I added a column to the database not present in the csv file that I would like to populate based on the value of another column in the database.

For example, in my csv file and also in the database I have the vehicle type column (car, motorcycle, boat) and in the database I added the vehicle_id column that I would like to populate based on the value (car = 1, motorcycle = 2, boat = 3).

Is it possible to add such a step to the import script?

Thanks a lot to everyone.

CodePudding user response:

In your import script before your insert query. create if statement

if($vehicle_type == "car"){
    $vehicle_id = 1;
}elseif($vehicle_type == "motorcycle"){
    $vehicle_id = 2;
}elseif($vehicle_type == "boat"){
    $vehicle_id = 3;
}

CodePudding user response:

OK! A thousand thanks! perfect!

  • Related