我有这个剧本。
<?php
include 'config.php'; // Mysql connection
$cislonakupucount=$_GET['cislonakupucount'];
$op1=mysql_query("SELECT * FROM `count_size` WHERE `cislonakupu`='$cislonakupucount'");
while ($row=mysql_fetch_array($op1)) {
$id=$row['idproduktu'];
$op=mysql_query("SELECT * FROM `count_size` WHERE `cislonakupu`='$cislonakupucount' AND `idproduktu`='$id'");
}
while ($row=mysql_fetch_array($op)) {
$idproduktu=$row['idproduktu'];
$s=$row['S']; // only number of chosen size
$m=$row['M'];
$l=$row['L'];
$xl=$row['XL'];
$vybrvel=$row['vybrvel']; // chosen size (of product)
if($vybrvel == "S"){
$b=mysql_query("UPDATE `products` SET `S`=S-$s WHERE `serial`='$idproduktu'");
}elseif($vybrvel == "M"){
$b=mysql_query("UPDATE `products` SET `M`=M-$m WHERE `serial`='$idproduktu'");
}elseif($vybrvel == "L"){
$b=mysql_query("UPDATE `products` SET `L`=L-$l WHERE `serial`='$idproduktu'");
}elseif($vybrvel == "XL"){
$b=mysql_query("UPDATE `products` SET `XL`=XL-$xl WHERE `serial`='$idproduktu'");
}
?>
如果“count_size”仅包含一行,则它有效。例如(cislonakupu = 123,S = 1,idproduktu = 1)。 但是,如果“count_size”包含两行:例如(cislonakupu = 123,S = 1,idproduktu = 1),(cislonakupu = 123,S = 1,idproduktu = 2),mysql查询只扣除一个大小(例如行)第1号)。 如何正确扣除?