如何计算购物车中商品的动态价格并输出总价

瑞泽科技

当用户将商品添加到购物车时,它将保存在我的临时数据库表 user_cart 中,并且购物车页面中将有商品的输出,用户将在购物车中看到他们的商品。所以我使用的php代码是while循环来输出项目。如何计算所有项目价格并将其输出到总部分?

<table class="table table-hover">
    <thead>
        <tr>
            <th>Product</th>
            <th>Quantity</th>
            <th class="text-center">Price</th>
            <th class="text-center">Total</th>
            <th> </th>
        </tr>
    </thead>
    <tbody>
        <tr>
        <?php
            $count = 1;
            $cart_query = "Select * from user_cart where email = '$email'";
            $cart_res = mysqli_query($con,$cart_query);
            while($cart_row = mysqli_fetch_assoc($cart_res)) {
        ?>
            <td class="col-sm-8 col-md-6">
            <div class="media">
                <a class="thumbnail pull-left" href="#"> <?php
                $image_count = 1;
                $product_name = stripslashes($cart_row["product_name"]);
                $image_query = "Select * from tbl_products where item_category = 'Laptop' AND item_name = '$product_name'";
                $image_res = mysqli_query($con,$image_query);
                while($row = mysqli_fetch_assoc($image_res)){
                $imageData = $row["images"];
                echo '<img src ="data:image/jpeg;base64,'.base64_encode($imageData).'"class="img-responsive" style = "width:100px; height:80px;"/>';?>
                <?php $count++; } ?>
                </a>
                <div class="media-body">
                 <h4 class="media-heading"><a href="#"><?php echo stripslashes($cart_row["product_name"]);?></a></h4>
                <h5 class="media-heading"> by <a href="#"><?php echo $cart_row["brand"];?></a></h5>
                <span>Status: </span>
                <span class="text-success">
                <strong><?php echo $cart_row["item_available"];?></strong>
                </span>
                </div>
            </div></td>
            <td class="col-sm-1 col-md-1" style="text-align: center">
                <input type="email" class="form-control" id="exampleInputEmail1" value="<?php echo $cart_row["quantity"];?>">
            </td>
            <td class="col-sm-1 col-md-1 text-center">
            <strong><?php echo $cart_row["item_price"];?></strong></td>
            <td class="col-sm-1 col-md-1 text-center" id = "item_total_price">
            <strong><?php echo $cart_row["item_total_price"];?></strong></td>
            <td class="col-sm-1 col-md-1">
            <form action  = "functions/delete.php" method = "post">
            <button type="submit" class="btn btn-danger">
             <input type = "hidden" value = "<?php echo $cart_row['cart_id'];?>" name = "cart_id">
            <span class="glyphicon glyphicon-remove"></span> Remove
            </button></td>
            </form>
            </tr>
            <?php $count++; } ?>
            <tr>
            <td>   </td>
            <td>   </td>
            <td>   </td>
            <td><h5>Subtotal</h5></td>
            <td class="text-right" id = "sub_total">
            <h5><strong></strong></h5></td>
            </tr>
            <tr>
            <td>   </td>
            <td>   </td>
            <td>   </td>
            <td><h3>Total</h3></td>
            <td class="text-right">
              <h3><strong>$31.53</strong></h3>
            </td></tr>
            <tr>
            <td>   </td>
            <td>   </td>
            <td>   </td>
            <td>
            <button type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-shopping-cart">
            </span> Continue Shopping</button></td>
            <td>
            <button type="button" class="btn btn-success">
                Checkout <span class="glyphicon glyphicon-play"></span>
            </button></td>
            </tr>
            </tbody>
            </table>
郑爽

计算总价时麻烦添加到购物车并记录在表中,另一个是SQL计算:“select sum('goos_price') * buys_count as total_price from your_table”;if use php :$total_price = 0;foreach ($cart_data as $key=>$val){ $total_price = $val['goos_price'] * $val['buys_count'];}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

WooCommerce 中的购物车总价覆盖

来自分类Dev

如果购物车中已存在商品-reactjs,如何更新购物车数量?

来自分类Dev

Rails:如何在购物车中添加“删除商品”?

来自分类Dev

如何从WooCommerce购物车中获取商品类别?

来自分类Dev

商品未显示在购物车中

来自分类Dev

购物车难度中的选定列表动态计算

来自分类Dev

购物车难度中的选定列表动态计算

来自分类Dev

无法弄清楚如何在“ jQuery”中的购物车中添加“总价”部分

来自分类Dev

无法弄清楚如何在“ jQuery”中的购物车中添加“总价”部分

来自分类Dev

总价未显示在PHP的购物车中

来自分类Dev

Woocommerce 格式的购物车计算费用的价格显示

来自分类Dev

从 WooCommerce 中的自定义字段值动态更改购物车商品价格

来自分类Dev

AngularJS中的购物车计算

来自分类Dev

如何使用vuex刷新后如何将商品保留在购物车中

来自分类Dev

是否可以在magento中更改购物车中的价格?

来自分类Dev

在Magento中,如何获取购物车中含税的每种产品的正常价格?

来自分类Dev

添加商品时如何添加到购物车?

来自分类Dev

追加购物车,如何打折某些商品?

来自分类Dev

从购物车会话中删除商品。拉拉韦尔

来自分类Dev

检查购物车中的重复商品并更新数量(ReactJS)

来自分类Dev

在购物车中添加商品数量

来自分类Dev

修改购物车中的商品名称

来自分类Dev

无法显示购物车中的商品数

来自分类Dev

永久存储购物车中100多个商品

来自分类Dev

Woocommerce:从购物车中的商品获取所选属性

来自分类Dev

使用Django更新购物车中的商品

来自分类Dev

从购物车会话中删除商品。拉拉韦尔

来自分类Dev

无法获得购物车中商品的总和

来自分类Dev

没有API时如何在首页从购物车中获取商品

Related 相关文章

  1. 1

    WooCommerce 中的购物车总价覆盖

  2. 2

    如果购物车中已存在商品-reactjs,如何更新购物车数量?

  3. 3

    Rails:如何在购物车中添加“删除商品”?

  4. 4

    如何从WooCommerce购物车中获取商品类别?

  5. 5

    商品未显示在购物车中

  6. 6

    购物车难度中的选定列表动态计算

  7. 7

    购物车难度中的选定列表动态计算

  8. 8

    无法弄清楚如何在“ jQuery”中的购物车中添加“总价”部分

  9. 9

    无法弄清楚如何在“ jQuery”中的购物车中添加“总价”部分

  10. 10

    总价未显示在PHP的购物车中

  11. 11

    Woocommerce 格式的购物车计算费用的价格显示

  12. 12

    从 WooCommerce 中的自定义字段值动态更改购物车商品价格

  13. 13

    AngularJS中的购物车计算

  14. 14

    如何使用vuex刷新后如何将商品保留在购物车中

  15. 15

    是否可以在magento中更改购物车中的价格?

  16. 16

    在Magento中,如何获取购物车中含税的每种产品的正常价格?

  17. 17

    添加商品时如何添加到购物车?

  18. 18

    追加购物车,如何打折某些商品?

  19. 19

    从购物车会话中删除商品。拉拉韦尔

  20. 20

    检查购物车中的重复商品并更新数量(ReactJS)

  21. 21

    在购物车中添加商品数量

  22. 22

    修改购物车中的商品名称

  23. 23

    无法显示购物车中的商品数

  24. 24

    永久存储购物车中100多个商品

  25. 25

    Woocommerce:从购物车中的商品获取所选属性

  26. 26

    使用Django更新购物车中的商品

  27. 27

    从购物车会话中删除商品。拉拉韦尔

  28. 28

    无法获得购物车中商品的总和

  29. 29

    没有API时如何在首页从购物车中获取商品

热门标签

归档