Reputation: 73
I got this code to compare and find differences between 2 CSV files (with 1 column each and 1 EAN code per line) with array_diff in both direction:
<?php
mysql_connect('LOCALHOST', 'db', 'passwd') or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
$update_table = "ps_product";
$file1 = file('1.csv');
$file2 = file('2.csv');
$diff = array_diff($file1, $file2);
$diff2 = array_diff($file2, $file1);
$diffjoined = array_merge($diff, $diff2);
?>
Now I have to know if in the merged array, there are corresponding values inside the db and then set quantity to 0:
If "a value inside array ($diffjoined) was found in DB"
foreach "ean code found in DB"
mysql_query ("UPDATE $update_table SET quantity='0' WHERE ean13 IN ($diffjoined) ");
Upvotes: 0
Views: 87
Reputation: 953
I'm assuming that your $diffjoined
is a list of ean13's from your code.
Your SQL query is close
$eans = "'".implode("','", $diffjoined)."'";
$q = "UPDATE $update_table SET quantity='0' WHERE ean13 IN ($eans)";
mysql_query($q);
Upvotes: 1