Rating System

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alexmaster_2004
Forum Commoner
Posts: 35
Joined: Wed Sep 14, 2005 8:44 am

Rating System

Post by alexmaster_2004 »

HI
i'm try to add a rating section to my web site.
i want to make it a pro one just like what you can find here
download.com i like their way.
also here is fine windows market place
i had tried to do it myself but i didn't come to anything.
so i hope if you can help me.
Thanks in advance
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Store the number of votes made, and the total of all the ratings.

So, if someone gave 'mycode' a 3, someone else gave it a 4, and someone else gave it a 1, it would have 3 total votes and a rating of 8.
Store these numbers in a database, and when you need to pull out the average rating, divide 8 (total of the votes) by 3 (total number of votes).

Yaaargh
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

If you want stars, have an image for 1 out of 5, 2 out of 5 ... 5 out of 5. Call them star_1.gif ... star_5.gif.

Now do a ceil on your average score, and call the correct gif, maybe:

Code: Select all

$stars = ceil($votetotal / $totalnumberofvotesvotes);
print "<img src=\"star_".$stars.".gif\" />";

Yarrrrrgh
alexmaster_2004
Forum Commoner
Posts: 35
Joined: Wed Sep 14, 2005 8:44 am

Post by alexmaster_2004 »

Hi
first thanks for ur reply
but i still want to know how the user will enter his rate.
as you see in download.com the user hover the mouse over the stars
and then choose his rating.i want to know how to do this.
all what i want is enable the user to choose the rate by fillup the stars
Thanks
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

im not registered with download.com so i don't know exactally how they do it. just have each star as a link, if there are 5 stars then the 1st star has a get var of being 1, 2nd star would be 2 and so on. then just use the get var on the page that updates the db to find out which ranking they chose
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Download.com uses javascript to change the colour of the stars depending on where the user has his mouse over the image - Google for 'onmouseover image' and you'll find a some good starts on how it's done.
Post Reply