【发布时间】:2012-11-04 11:47:23
【问题描述】:
我有一个表格,其中显示了 ($_SESSION['cart'],里面有一个表格,我可以手动将我想要的数量引入我的 ($_SESSION['cart'] 产品。
<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['cart']) 数量
<?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['qty']”中我还应该说将 QUANTITY UPDATED 减去 DATA BASE QUANTITY 但我不知道该怎么做。有帮助吗?
【问题讨论】:
标签: php