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? Quote Link to comment 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... Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted July 26, 2013 Solution 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. Quote Link to comment 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.