1
我一直在製作一個小型購物車。我試圖顯示購物車 價值,並有總計。我已成功顯示購物車產品,但我無法顯示總計。它一直在顯示錯誤'資源ID#5'。請在下面查看我的代碼。如何獲得購物車中相同用戶ID的兩個值的總和
viewcart.php
<?php
include('config.php');
session_start();
echo $session=$_SESSION['user_email'];
echo $query=mysql_query("SELECT product_price, SUM(product_price) FROM cart where user_email='$session' GROUP BY user_email");
$total = mysql_fetch_array($query);
$query1=mysql_query("select * from cart where user_email='$session'");
$num_rows = mysql_num_rows($query1);
if($num_rows>0){
echo "<center>";
echo "<table style='width:80%' border=5px><tr><th>Product Name</th>
<th>Product Details</th><th>Product Price</th></tr>";
while($query2=mysql_fetch_array($query1))
//if($query2>0){
{
echo "<tr><td>".$query2['product_name']."</td>";
echo "<td>".$query2['product_details']."</td>";
echo "<td>".$query2['product_price']."</td>";
echo "<td><a href='remove.php?id=".$query2['id']."'>Remove Product</a></td>";
echo "</tr>";
}
echo "<tr><td>Total:</td><td>".$total['product_price']."</td></tr>";
?>
</table>
</center><br/><br/><?php } else { echo "<center>No product available for display!!</center>"; }?>
1.擺脫的MySQL和使用mysqli的,它棄用 – clearshot66