dlebowski Posted August 31, 2007 Share Posted August 31, 2007 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...); Quote Link to comment https://forums.phpfreaks.com/topic/67455-solved-importing-csv-file-and-need-to-ignore-columns-in-the-file/ Share on other sites More sharing options...
lemmin Posted August 31, 2007 Share Posted August 31, 2007 If you set the default value of the column to something, you don't need to put it in the insert. Quote Link to comment https://forums.phpfreaks.com/topic/67455-solved-importing-csv-file-and-need-to-ignore-columns-in-the-file/#findComment-338641 Share on other sites More sharing options...
dlebowski Posted August 31, 2007 Author Share Posted August 31, 2007 So are you referring to the field in the database? Make sure it has a default value? Quote Link to comment https://forums.phpfreaks.com/topic/67455-solved-importing-csv-file-and-need-to-ignore-columns-in-the-file/#findComment-338647 Share on other sites More sharing options...
dlebowski Posted August 31, 2007 Author Share Posted August 31, 2007 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()); Quote Link to comment https://forums.phpfreaks.com/topic/67455-solved-importing-csv-file-and-need-to-ignore-columns-in-the-file/#findComment-338670 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.