-2

以下のコードは、カートの最後のエントリのみを更新します。ループに少し苦労していて、立ち往生しています。

 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'] .'">
4

1 に答える 1

0

フォームのすべての入力にIDを追加した後。上記のコードに以下を追加しましたが、動作します!!

        foreach ($_POST['prodid'] as $id=>$prod){
            if ($id==$k){
                $pid = $prod;
            }
        }
        foreach ($_POST['cat'] as $catid=>$cat){
            if ($catid==$k){
                $sp_type = $cat;
            }
        }

残りのコード...

于 2012-11-09T18:08:45.193 に答える