簡體   English   中英

如何更新購物車數量小計?

[英]how to update subtotal in shoppping cart quantity?

當我將更多數量添加到我選擇的產品之一中時,一旦我按“更新”按鈕,小計就沒有給我正確的結帳總計,在計算顯示錯誤的最終總計時,它只能正確讀取單個數量。

            <table align="center" width="700" bgcolor="white">

                <tr align="center">
                    <th>Remove</th>
                    <th>Product(S)</th>
                    <th>Quantity</th>
                    <th>Total Price</th>
                </tr>

    <?php 
    $total = 0;

    global $connection; 

    $ip = getIp(); 

    $sel_price = "select * from cart where ip_add='$ip'";

    $run_price = mysqli_query($connection, $sel_price); 

    while($p_price=mysqli_fetch_array($run_price)){

        $pro_id = $p_price['p_id']; 

        $pro_price = "select * from Product where Product_ID='$pro_id'";

        $run_pro_price = mysqli_query($connection,$pro_price); 

        while ($pp_price = mysqli_fetch_array($run_pro_price)){

        $product_price = array($pp_price['Price']);

        $product_title = $pp_price['Product_Name'];

        $product_image = $pp_price['Image']; 

        $single_price = $pp_price['Price'];

        $values = array_sum($product_price); 

        $total += $values; 

                ?>

                <tr align="center">
                    <td><input type="checkbox" name="remove[]" value="<?php echo $pro_id;?>"/></td>
                    <td style="border:1; color:black;"><?php echo $product_title; ?><br>
                    <img src="admin_area/product_images/<?php echo $product_image;?>" width="60" height="60"/>
                    </td>
                    <td><input type="text" size="4" name="qty" value="<?php echo $_SESSION['qty'];?>"/></td>

                    <?php 

                    if(isset($_POST['update_cart'])){

                        $qty = $_POST['qty'];

                        $update_qty = "update cart set qty='$qty'";

                        $run_qty = mysqli_query($connection, $update_qty); 

                        $_SESSION['qty']=$qty;

                        $total = $total*$qty;
                    }


                    ?>


                    <td><?php echo "$" . $single_price; ?></td>
                </tr>


            <?php } } ?>






            <tr>
                    <td colspan="4" align="right"><b>Sub Total:</b></td>
                    <td><?php echo "$" . $total;?></td>
                </tr>

                <tr align="center">
                    <td colspan="2"><input type="submit" name="update_cart" value="Update Cart"/></td>
                    <td><input type="submit" name="continue" value="Continue Shopping" /></td>
                    <td><button><a href="checkout.php" style="text-decoration:none; color:black;">Checkout</a></button></td>
                </tr>

            </table> 

        </form>

我認為問題出在這里(不確定)

<?php 

                        if(isset($_POST['update_cart'])){

                            $qty = $_POST['qty'];

                            $update_qty = "update cart set qty='$qty'";

                            $run_qty = mysqli_query($connection, $update_qty); 

                            $_SESSION['qty']=$qty;

                            $total = $total*$qty;
                        }


                        ?>

這是實際頁面的鏈接,另一個是我的數據庫的鏈接

http://www.ya-techno.com/up/uploads/1430742773071.png http://www.ya-techno.com/cn/up/uploads/1430742841161.png

您可以使用jquery ajax post方法提取它們...

使用下面的php代碼提取購物車單個小計:

$this->cart->contents()['eccbc87e4b5ce2fe28308fd9f2a7baf3']['subtotal'] 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM