How to make ratings?

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
ambal13
Forum Newbie
Posts: 5
Joined: Tue Feb 24, 2009 7:25 pm

How to make ratings?

Post by ambal13 »

Hello

I'm trying to make a ratings system for a website and I'm having some trouble with it. I can definetly make the ratings work if I knew how to store the ratings. Should I store them in a mySql database? And If so, how? do I make a table with 1000 entries and gradually put in the ratings that come in one by one and hope noone rates something more than a 1000 times? (<-- i know this sounds stupid). Or can I somehow store multiple ratings in one entry of a table?

To rate, there will be a form with with 6 radio buttons for 0,1,2,3,4,5

Thanks
killingbegin
Forum Newbie
Posts: 20
Joined: Sun Feb 08, 2009 5:07 am

Re: How to make ratings?

Post by killingbegin »

ok so there will be

---Rate the web site---
0,1,2,3,4,5,6,7,8,9,10
[SUBMIT]

make an sql table with 10 rows from it will be 0-10

3 columns id----rating_num---counter


so now lets go if the user press 2 rating and submit it will go to a php page and find the
if statment that it will be

if the radio value is 2
$count = 1;
$last_count = Select counter from the table that rating_num is 2
etc etc etc

$count = $count + $last_count;

so here if 4 ppl have cklicked the 2 value the $last_count will give you 4
and the $count will give you 5

that have some issues like if the rating box is a 300-300 box somewhere in page it will refresh thepage
so the best way to do that is with javascript.

well that is my option to do this.i think there will be more easy way for that.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: How to make ratings?

Post by josh »

Store the raw ratings in one table, with a foreign key into the table you're rating. In the table you're rating add a column for total_points and rating_count, use the latter as a divisor to calculate the median rating, use the "raw" table to detect multiple votes, this way you don't have to sum over millions of rows on each page hit, but you can also defer to the raw table on the less common scenario where someone is leaving a review and you need to ensure its not a duplicate
ambal13
Forum Newbie
Posts: 5
Joined: Tue Feb 24, 2009 7:25 pm

Re: How to make ratings?

Post by ambal13 »

thank you, i understand now. i knew i was making it to be too complicated :)
Post Reply