Rating average is unable to compute.
Posted: Thu Dec 19, 2002 8:35 pm
I was working on a code addition to have ratings display selected from the discussions table, which works and displays on each individual discussion.
However the problem for gathering up the total counts of ratings submitted from each discussion, it will display only zero as the number, and doesn't seem to recognize computing the average of all the ratings.
The $outcome I thought should act like any mysql result. And the $access variable was intended to access within the array.
Am I missing something or misarranged something?
However the problem for gathering up the total counts of ratings submitted from each discussion, it will display only zero as the number, and doesn't seem to recognize computing the average of all the ratings.
The $outcome I thought should act like any mysql result. And the $access variable was intended to access within the array.
Am I missing something or misarranged something?
Code: Select all
<?php
@$outcome=mysql_query("SELECT rating FROM discussions WHERE articleID='$articleID'");
require("admin/failure.php");
while($access=mysql_fetch_array($outcome))
{
if (!$outcome) {
print "Error: no results returned (rating)";
}
$rate_count = mysql_num_rows($outcome);
if ($rate_count) {
for ($i=0; $i<$rate_count; $i++) {
$rating = mysql_fetch_array($outcome);
$total += $rating[rating];
}
$average = $total / $rate_count;
}
$average=$access["average"];
echo '<p><font face="Arial, Helvetica, sans-serif" size="2">',number_format($average,1,'.',''),'</font></p>';
}
?>