Re: Importing data in to mysql with some control

From: Date: Mon, 16 Apr 2007 09:52:14 +0000
Subject: Re: Importing data in to mysql with some control
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-252992@lists.php.net to get a copy of this message
Richard Kurth wrote: > I am trying to write a import script for loading data into an existing mysql > table. I want to show the import data on the screen and let the user select > the column number to go with which mysql field. Now some of the fields are > mandatory like firstname lastname email address and so on........... But > some of the fields might be custom fields these would be stored in a > different table and the mysql fields would be custom1 custom2 ......... So > the user would select what column go's with which field. No I know that some > of this would have to be done server side. So I was thinking of using Ajax > or just JavaScript. Does anybody know of any examples that show something > like this being done. The only examples I have seen just shows data being > imported into the database form csv file with out choosing where the data > should go. It has to be in order when you run the script. Any ideas on where > to look and how to get this started. 1. user uploads CSV file 2. you cache the file 3. you parse the file for available headers/columns 4. you display an interface for mapping available columns to required/optional fields (the hard part is probably making this part user-friendly and fool-proof.) 5. the user submits their mapping selection 6. you loop through the 'rows' in the cached CSV file - using the mapping selection data that was submitted in order to generate suitable sql INSERT statements ... say the user mapped column X to field Y and column X is the third column of data in the CSV file then for every row you would take the third piece of data and make a snippet of SQL that ends up looking like: "X='mydata'" 'X' would be retrieved from the mapping info that your given, and 'mydata' would be the data from the 3rd column of a given row in the CSV file. hth >

« previous php.general (#252992) next »