kpetsche20 Posted July 6, 2008 Share Posted July 6, 2008 I'm trying to get the rating of the column rating in the table rating, when I execute that code all that displays is Resource id #8 <? $getaverage = "SELECT AVG(rating) FROM rating"; $runaverage = mysql_query($getaverage) or die(mysql_error()); echo $runaverage; while($data = mysql_fetch_assoc($runaverage)) { echo "".$data['rating'].""; } ?> Link to comment https://forums.phpfreaks.com/topic/113421-problem-with-getting-average-to-display-from-mysql/ Share on other sites More sharing options...
Barand Posted July 6, 2008 Share Posted July 6, 2008 mysql_query() returns a Resource ID, so that's what your code prints. Use an alias for the average: $getaverage = "SELECT AVG(rating) as avrating FROM rating"; $runaverage = mysql_query($getaverage) or die(mysql_error()); Only one row so no need for the while loop echo mysql_result ($runaverage, 0, 'avrating'); Link to comment https://forums.phpfreaks.com/topic/113421-problem-with-getting-average-to-display-from-mysql/#findComment-582779 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.