Page 1 of 1

How to make ratings?

Posted: Fri Mar 27, 2009 8:48 am
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

Re: How to make ratings?

Posted: Fri Mar 27, 2009 9:50 am
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.

Re: How to make ratings?

Posted: Fri Mar 27, 2009 10:46 am
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

Re: How to make ratings?

Posted: Fri Mar 27, 2009 7:32 pm
by ambal13
thank you, i understand now. i knew i was making it to be too complicated :)