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...);

Link to comment
Share on other sites

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());

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.