php-newbies Posted February 23, 2012 Share Posted February 23, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/257580-help-importing-csv-file-to-a-specific-column-in-a-database-table/ Share on other sites More sharing options...
requinix Posted February 23, 2012 Share Posted February 23, 2012 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` Quote Link to comment https://forums.phpfreaks.com/topic/257580-help-importing-csv-file-to-a-specific-column-in-a-database-table/#findComment-1320261 Share on other sites More sharing options...
php-newbies Posted February 23, 2012 Author Share Posted February 23, 2012 Thank you for your response. I will try it out later and will report back. thanks again for your help. Quote Link to comment https://forums.phpfreaks.com/topic/257580-help-importing-csv-file-to-a-specific-column-in-a-database-table/#findComment-1320271 Share on other sites More sharing options...
php-newbies Posted February 23, 2012 Author Share Posted February 23, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257580-help-importing-csv-file-to-a-specific-column-in-a-database-table/#findComment-1320353 Share on other sites More sharing options...
requinix Posted February 23, 2012 Share Posted February 23, 2012 Use whatever phpMyAdmin offers for uploading and importing. What I gave is (apparently) not what you'd need to use. Quote Link to comment https://forums.phpfreaks.com/topic/257580-help-importing-csv-file-to-a-specific-column-in-a-database-table/#findComment-1320380 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.