" readonly> 最佳答案 你想要的变量不太清楚。也就是说,您-6ren">
gpt4 book ai didi

javascript - 如何计算从php中选择的每个项目的购物车总数?

转载 作者:行者123 更新时间:2023-11-28 03:08:28 24 4
gpt4 key购买 nike

我是一个初学者,正在寻求解决这个问题!

如何计算购物车中每件商品的总计以及如何计算总计?

这是我的代码

<td class="p-price first-row"><?php echo 'LBP '.number_format($r['product_price'],0)?>/KG</td>
<input type="hidden" class="unitprice" id="unitprice" value="<?php echo $r['product_price']?>">
<input type="text" id="quantity" class="quantity" value="<?php echo $weight ?>" readonly>
<td class="total-price first-row"><input class="total" id="total" readonly></td>

<input type="int" value="" id="grandtotal" class="grandtotal" readonly>

最佳答案

你想要的变量不太清楚。也就是说,您似乎正在寻找类似的东西:

$grandTotal = 0;
foreach ($_SESSION as $key => $values) {
if (strpos($key, "pid") !== false) {
$sql = "select * from products LEFT JOIN category on products.category_id = category.category_id where product_id = $_SESSION[$key]";
$result = $connect->query($sql);
$r = mysqli_fetch_assoc($result);
$w = "weight";
$w .= (string)$r['product_id'];
$weight = $_SESSION[$w];
$total = $r['product_price'] * $weight;
$grandTotal += $total;
}
}

关于javascript - 如何计算从php中选择的每个项目的购物车总数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60377221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com