Hriskesh Ashokan Hriskesh Ashokan - 1 year ago 74
PHP Question

MySQL PHP for SELECT AVG(column) returns Resource ID 3

I want to get the average value of my ratings column for my review table.
This is what has been done so far

$averagereviewquery = "SELECT AVG(review_rating) from reviews where product_id=".$primarykey;

if($insert_review){ //successful insert
echo $averagereviewresult;

what happens is averagereviewresult returns "Resource Id 3". What do i do to change it to show me the average value?


mysql_query does return a resource. You need to expicitly read the value from your query in order to get the result. One way is to use mysql_result:

echo mysql_result($averagereviewresult, 0);