dev1902 Posted July 25, 2013 Share Posted July 25, 2013 Hello, can someone help me with a code to access a specific column in my .csv excel file to populate a text filed? Link to comment https://forums.phpfreaks.com/topic/280513-populating-text-fields/ Share on other sites More sharing options...
requinix Posted July 25, 2013 Share Posted July 25, 2013 Probably. You'd have to post your code, explain what it's supposed to do, explain what it actually us, maybe give us some background information... Link to comment https://forums.phpfreaks.com/topic/280513-populating-text-fields/#findComment-1442180 Share on other sites More sharing options...
dev1902 Posted July 26, 2013 Author Share Posted July 26, 2013 OK, i have a .csv excel file that has a lot of data. I am working with the human genome. I am creating a web database to store information on over 25,000 genes. All the information is in the the .csv file, and i need help with a php code to access a specific column in the file to populate a text field. Link to comment https://forums.phpfreaks.com/topic/280513-populating-text-fields/#findComment-1442276 Share on other sites More sharing options...
mac_gyver Posted July 26, 2013 Share Posted July 26, 2013 if this is a one time activity, you can use a mysql LOAD DATA LOCAL INFILE ... query - http://dev.mysql.com/doc/refman/5.6/en/load-data.html there probably are csv import scripts that analyze your csv header and database columns and allow you to pick and map which csv column(s) are imported into which database table column(s). have you tried searching the Internet for an existing script that will do this? otherwise, you will need to write some php code to open, read, and parse the data out of your csv file and form and run the query(ies) to insert the data into your database table. 25k entries is not that much, you should be able to read the entire file into memory at one time to speed up the processing. you can use php's file() function to get all the lines into an array. you can then explode/access the correct column of data. i'm partial to using array_map() and a short user written function to do this without having to loop of the data in your code. you can than split the resulting array of data into chunks (see the array_chunk() function) of about 5k entries each. then loop through the chunks of arrays and implode the data within each chunk to form a multi-value INSERT query. Link to comment https://forums.phpfreaks.com/topic/280513-populating-text-fields/#findComment-1442290 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.