|
-
Aug 17th, 2002, 07:38 AM
#1
Thread Starter
Fanatic Member
Rating System
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?
-
Aug 17th, 2002, 11:12 AM
#2
Lively Member
well this is how I did it.
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\">";
}
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.
Just Imagine what you can do with the power of php.
257 Tutorials and counting.
529 Snippets and growing.
Add yours today @
SnippetLibrary.com
-
Aug 18th, 2002, 06:40 AM
#3
Thread Starter
Fanatic Member
Thanks thats what I needed
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|