下面的代码只会更新我购物车的最后一个条目。我在循环中有点挣扎,我只是卡住了。
if (isset($_POST['quantity'])) { // Update quantities in the cart
foreach ($_POST['quantity'] as $k => $qty) { //Full name on form: name="quantity[' . $row['prodid'] . ']"
$pid = $_POST ['prodid'];
$sp_type = $_POST ['cat'];
if (isset($sp_type, $pid)) {
// Determine the quantity:
$qty = (filter_var($qty, FILTER_VALIDATE_INT, array('min_range' => 0)) !== false) ? $qty : 1;
// Update the quantity in the cart:
$r = mysqli_query($dbc, "CALL update_cart('$uid', '$sp_type', $pid, $qty)");
}
} // End of FOREACH
}
cart.html 上的代码:
这是购物车的 html 表单的代码:
<input type="hidden" name="prodid[' . $row['prodid'] . ']" value="' .$row ['prodid'] .'" /></td>
<td align="center"><input type="text" name="quantity[' . $row['prodid'] . ']" value="' . $row['quantity'] . '" size="2" class="small" /></td>
<td align="right">£' . $price . '</td>
<td align="right">£' . number_format($subtotal, 2) . '</td>
<td align="right"><a href="/wishlist.php?id=' . $row['prodid'] . '&action=move&qty=' . $row['quantity'] .'&cat=' .$row ['cat_id'] .'">