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>"; }?>
答案 0 :(得分:1)
$query = mysql_query("SELECT SUM(product_price) as sum FROM cart where user_email='".mysql_real_escape_string($session)."'");
$total = 0;
if ($result=mysql_fetch_assoc($query)) {
$total = $result['sum'];
}