Jump to content

Populating Text Fields


dev1902
Go to solution Solved by mac_gyver,

Recommended Posts

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
Share on other sites

  • Solution

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.