如何增加数量并计算购物车页面中的总价格和总计。 [英] How to increase quantity and calculate total price and grand total in cart page.

查看:101
本文介绍了如何增加数量并计算购物车页面中的总价格和总计。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为用户创建了购物车详细信息页面,使用Cookie添加到购物车中添加了哪些产品。我展示了产品图片,名称,价格,数量,总价格以及删除添加的产品。如果用户增加产品的量化,应自动计算总价。如果用户减少数量应该总价格下降。我设置默认的数量是1.



以下是我的代码我试过的。



我尝试了什么:



I created cart detail page to user what product added in add to cart using cookies. I showed product image, name, price, quantity, total price and remove added product. If user increase quantiy of product, should total price automatacally calculate. If user decrease quantity should total price decrease. I set default quanity is 1.

Below is my code what i tryed.

What I have tried:

<?php
	$pro_id = $_COOKIE['product_id'];   
	$pro_id = explode(',', $pro_id);
	$qua = 1;
	foreach ($pro_id as $val) {
		$ans = "SELECT * FROM wm_products WHERE pro_id='$val'";
		$result = $conn->query($ans);
		while($row = $result->fetch_assoc()){
		?>
			<tr class="cart_item">
				<td>
					<a href="single-product.html"><img src="products_images/<?php echo $row['pro_img']; ?>" alt="" width="180" height="180"></a>
				</td>
				<td>
					<a href="single-product.html"><?php echo $row['pro_name']; ?></a>
				</td>
				<td>
					<span class="amount">Rs. <?php echo $row['pro_price']; ?></span>
				</td>
				<td>
					<div class="quantity buttons_added">
					<form action="" method="post">
						<input type="submit" class="minus" name="minus" value="-">				
						<input type="text" size="4" class="input-text qty text" title="Qty" value="<?php echo $qua;?>" name="" max="29" min="0" step="1" >
						<input type="submit" class="plus" name="plus" value="+">
					</form>					
					</div>
				</td>
				<td>
					<span class="amount">Rs. <?php echo number_format($row['pro_price'] * $qua); ?></span>
				</td>
				<td>
					<a class="remove remove_cart" href="#" dataid="<?php echo $row['pro_id']; ?>">×</a>
				</td>
			</tr>
		<?php 
		}                                   
	}
?>

推荐答案

pro_id =


_COOKIE ['product_id'];
_COOKIE['product_id'];


pro_id = explode(',',
pro_id = explode(',',


这篇关于如何增加数量并计算购物车页面中的总价格和总计。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆