我有一個表,它顯示($ _SESSION ['cart']與一個窗體裏面,我可以手動引入我想要的數量到我的($ _SESSION [ '購物車']產品。Substract Session [cart]數量到股票數量在db
<form name="formulario2" method="POST" target="oculto"><input type="hidden" name="action" value="update">
foreach($_SESSION['cart'] as $product_id => $quantity) {
echo "<td align=\"center\"><input type = \"text\" size=\"1\" name=\"qty[$product_id]\" value =\"{$_SESSION['cart'][$product_id]}\"></td>";
}
</form>
然後我用下面的更新($ _SESSION [ '購物車'])數量
<?php
if(isset($_POST['action']) && ($_POST['action'] =='update')){
//
foreach ($_POST['qty'] as $product_id=> $quantity){
$qty = (int)$quantity;
if ($qty > 0){
$_SESSION['cart'][$product_id] = $qty;
}
}
}
?>
現在我想。減去這些數量我有已更新到($ _SESSION ['cart '])與我的數據庫中的STOCK數量進行比較。
我認爲,在過去「的foreach($ _ POST [‘數量’]」我也要說。減去更新到數據庫數量QUANTITY但我不知道該怎麼做。任何幫助嗎?
http://en.wikipedia.org/wiki/SQL_Update –