Jump to content

[SOLVED] Importing .csv file and need to ignore columns in the file...


dlebowski

Recommended Posts

I am importing a .csv file and it works great until i have to ignore a column in the file.  How do I setup the insert query to ignore that column?  Through the import the user selects which fields in the .csv file correspond with the tables in the database using variables.  On occasion they have a field in the file that needs to be ignored.  Thanks for the help.

 

Change this:

INSERT into table_name (column1, column2....)
values (value1, value2...);

 

To something like this:

INSERT into table_name (IGNORE, CustomerID....)
values (value1, value2...);

Here is what my code looks like.  For example, often a file being imported may not want to populate $column1.  But I have to leave it in there because the file I try importing at a later date may actually need that column.  Let me know if I need to elaborate more.  Thanks.

 

$import="INSERT into lots(LotID,$column1,$column2,$column3,$column4,LotPayment,Online,Absentee,$column5,Date, $column6, $column7)";
       $import .=" values('', '" . cleancvs($data[0]) . "','" .  cleancvs($data[1]) . "',"; 
       $import .= " '" . cleancvs($data[2]) . "','" . cleancvs($data[3]) . "','$lotpayment', '$online', '','" . cleancvs($data[4]) . "','$dateimport', '" . cleancvs($data[5]) . "', '" . cleancvs($data[6]) . "')";
       mysql_query($import) or die(mysql_error());

Archived

This topic is now archived and is closed to further replies.

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