Php 如何为购物车获取相同用户id的两个值之和

Php 如何为购物车获取相同用户id的两个值之和,php,mysql,Php,Mysql,我一直在做一个小购物车。我正试图展示购物车 价值和总价值。我已成功显示购物车产品,但我 无法显示总计。它一直显示错误“资源id#5”。请检查我下面的代码 viewcart.php <?php include('config.php'); session_start(); echo $session=$_SESSION['user_email']; echo $query=mysql_query("SELECT product_price, SUM(product_price) F

我一直在做一个小购物车。我正试图展示购物车 价值和总价值。我已成功显示购物车产品,但我 无法显示总计。它一直显示错误“资源id#5”。请检查我下面的代码

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,它已被弃用
$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'];
}