doubo4336 2014-08-13 17:57
浏览 224

Mysql查询并查找是否存在值

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) ");
  • 写回答

1条回答 默认 最新

  • duandi2853 2014-08-13 18:43
    关注

    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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数