Reputation: 73
I have to compare 2 csv files where each file got 1 column:
file1.csv:
column1
9788800000000
9788800000001
9788800000002
9788800000003
...
file2.csv:
column1
9788800000000
9788800000001
9788800000002
9788800000006
9788800000007
9788800000008
...
I have to do something when some EAN code isn't found in the second csv file (file2.csv). For example the code 9788800000003 it's ONLY present in file1.csv.
Now, I have to update a table in DB when an EAN code in the first file, isn't found in the second file and set it to '0' (in this case, the ean 9788800000003 have to be change in 0 quantity):
mysql_query("UPDATE $update_table SET quantity='0' WHERE ean13='$ean13'")
how to compare the column for differences ?
Upvotes: 0
Views: 674
Reputation: 78994
Something like this:
$file1 = file('file1.csv');
$file2 = file('file2.csv');
$diff = array_diff($file1, $file2);
$list = implode(',', $diff);
$query = "UPDATE $update_table SET quantity='0' WHERE ean13 IN ($list)";
Upvotes: 3