$query = mysql_query("SELECT sum(rating) FROM stars WHERE post_id = 20");
echo $query;
It outputs:
Resource id #3
instead of 8, which is what the actual sum is.
$query = mysql_query("SELECT sum(rating) FROM stars WHERE post_id = 20");
echo $query;
It outputs:
Resource id #3
instead of 8, which is what the actual sum is.
Try the below. mysql_query returns a 'resource' that represents the resultset, and to get values you need to use one of the mysql_fetch_ functions.
$row = mysql_fetch_array($query);
echo $row[0];
As mentioned before, this is because the variable is a resource. Visit this link to learn more about PHP variable types.
It is only possible to echo strings or types that can be cast to strings. Such as int, float and objects implementing the __toString magic function.