Jump to content

Help Importing csv file to a specific column in a database table.


php-newbies

Recommended Posts

Hi all,

 

I have a table name states and I have 20 different states under this table.

 

I want to import csv file that contains names of cities that belongs to each states.

 

I am new to mysql and I am not such where to start. I have a web based application that I need to input these data. I have access to phpmyadmin through my hosting control panel.

 

Please help.

 

Thank you in advance for your help..

 

Regards,

 

Mark

Look into LOAD DATA INFILE. Something like

LOAD DATA INFILE "cities.csv" INTO TABLE `cities`
    FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' ESCAPED BY "\\"
    LINES TERMINATED BY "\n"
(`csvcity`, `csvstate`)
SET `city` = `csvcity`, `state`= `csvstate`

Hi again,

 

Where can I run this code? When I login into the phpmyadmin I can see the import button and when click , it ask for where to import data from but there is no place to place the code above. I have the csv files containing names of the cities for each individual states, each csv is unique to individual states. I know I have to import each csv 1 after the other for each states. But I cannot find where to run the code you provided above. Please help with abit of step by step.

 

Many thanks for your help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.