After i added one more quantity to one of my selected product the subtotal not given me a right checkout total once i press update button,its only read the single quantity right while calculating them showing wrong final total.
在我向我选择的产品之一添加了一个数量之后,一旦我按下更新按钮,小计没有给我一个正确的结帐总额,它只读取单个数量,同时计算它们显示错误的最终总数。
<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>
I think the problem is here (not sure)
我认为这个问题在这里(不确定)
<?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;
}
?>
Here are the links one for the actual page and the other one for my database
以下是实际页面的链接和我的数据库的另一个链接
http://www.ya-techno.com/up/uploads/1430742773071.png http://www.ya-techno.com/up/uploads/1430742841161.png
1 个解决方案
#1
you can use jquery ajax post method to extract them...
你可以使用jquery ajax post方法来提取它们......
use the php code below to extract cart single subtotal:
使用下面的PHP代码提取购物车单个小计:
$this->cart->contents()['eccbc87e4b5ce2fe28308fd9f2a7baf3']['subtotal']
#1
you can use jquery ajax post method to extract them...
你可以使用jquery ajax post方法来提取它们......
use the php code below to extract cart single subtotal:
使用下面的PHP代码提取购物车单个小计:
$this->cart->contents()['eccbc87e4b5ce2fe28308fd9f2a7baf3']['subtotal']