我有一个 $_POST 参数如下:
Array ( [qty-1] => 1 [uniprice-1] => 22.00 [qty-2] => 2 [uniprice-2] => 12.00 )
SQL 用于在 db 中更新:
foreach($_POST as $key => $value) {
$q = "UPDATE `table` SET ";
$q .= "stock=stock + '".$value."', ";
$q .= "price='".$value."' ";
$q .= "WHERE fid='".$fid."' AND vid='".$key."'";
echo $q.'<br />';
}
然而它的输出:
UPDATE `stock` SET stock=stock + '1', price='1' WHERE fid='9' AND vid='1'
UPDATE `stock` SET stock=stock + '22.00', price='22.00' WHERE fid='9' AND vid='1'
UPDATE `stock` SET stock=stock + '2', price='2' WHERE fid='9' AND vid='2'
UPDATE `stock` SET stock=stock + '12.00', price='12.00' WHERE fid='9' AND vid='2'
以如下形式更新查询的正确方法是什么?
UPDATE `stock` SET stock=stock + '1', price='22.00' WHERE fid='9' AND vid='1'
UPDATE `stock` SET stock=stock + '2', price='12.00' WHERE fid='9' AND vid='2'