0

$user = name of the table

producttotal
500
6105
131

$ordertotal = mysql_query("SELECT SUM(producttotal) FROM ".$user['username']."");

echo "Order total: ".$ordertotal;

why is the result "Order total: Resource id #7". I wanted to sum all the values below producttotal column.

Thanks in advance.

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by sun-tzu
0

You can not get data from a table in this way. Try this instead:

$user['username'] = 'bob123'; //Example

$query = mysql_query("SELECT SUM(producttotal) AS sum_total FROM ".$user['username']."");

$sum = mysql_fetch_array($query);

print $sum['sum_total']; //Should print the data correctly

As a side note, is the $user the name of a table or a row in a table? Because if it's a row in a table you should have:

$query = mysql_query("SELECT SUM(producttotal) AS sum_total FROM 'database' WHERE user=".$user['username']."");

Edited by sun-tzu: n/a

0

the $user is the name of the table.

I'll try it. thanks.

*Thanks! Worked.

Edited by ken.atienza: n/a

0

You're very welcome! Feel free to PM for further questions regarding SQL and PHP. And please mark this thread as solved.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.