$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.

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']."");

the $user is the name of the table.

I'll try it. thanks.

*Thanks! Worked.

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