如何总结从列中获得的用户总数"价格"值?
$statement = "SELECT user_id, SUM(price) FROM tbl_post WHERE user_id= ".'$_SESSION['user']';
$statement = mysql_query($statement);
$user_earning= mysql_fetch_row($statement);
echo $user_earning;
答案 0 :(得分:0)
您的SQL查询应如下所示:
select user_id,sum(price) from tbl_post where user_id=? group by user_id;
答案 1 :(得分:0)
你应该在select statment
中添加GROUP BY子句rendered !
写上面的查询而不是这个查询
$statement = "SELECT user_id, SUM(price)
FROM tbl_post
WHERE user_id= ".'$_SESSION['user']". "
GROUP BY user_id";
我不知道php,但是通过查看您的查询,您想要总结一个特定用户的所有价格。
答案 2 :(得分:0)
试试这个,你的查询中有错误:
$statement = "SELECT user_id, SUM(price) FROM tbl_post WHERE user_id= '".$_SESSION['user']."' ";
$statement = mysql_query($statement);
$user_earning= mysql_fetch_row($statement);
echo $user_earning[1];// echo $user_earning['price'];