I want to create a rating system, simple enough, but I wonder how to average the votes, then determine what is equals in stars. Sorta of like Vbulliten. How does it calculate, and hold the votes?
Printable View
I want to create a rating system, simple enough, but I wonder how to average the votes, then determine what is equals in stars. Sorta of like Vbulliten. How does it calculate, and hold the votes?
well this is how I did it.
I keep a total and a votes column. that way you can get an average for the votes. so like this forums does it counts the votes (1-5) and then it adds one to the total. so if 2 people voted and they both voted 5 the votes will = 10 and the total will = 2, so then you get 10 / 2 and a vote average of 5 and then you can display the correct number of stars.PHP Code:if ($num_row == '1') {
while($row=$db->fetch($voter)){
$num = $row["votes"];
$total = $row["total"];
}
$num = intval($num / $total);
echo "<b>User Rated at: </b><img src=\"images/".$num . "stars.gif\">";
} else {
echo "<b>User Rated at:</b> <img src=\"images/0stars.gif\">";
}
Thanks thats what I needed :cool: