Page 1 of 1
Building a rating system
Posted: Mon Nov 22, 2004 4:14 am
by angelena
Im interested in building a rating system for my photo gallery in php,and planning to add in the rating system...would like to know how shud i start...anyone could help??
Thx in advance ya

Posted: Mon Nov 22, 2004 4:22 am
by rehfeld
i would recomend looking at pre written scripts for ideas
hotscripts.com comes to mind
Posted: Mon Nov 22, 2004 6:18 am
by dull1554
have you tried to code anything? if you give us something we can help you from there
try this,
im assuming you have a database with all the info for each photo in the rows, add 3 new colums called ratetotal, numofrates, rate
then, make a rating script have it add the rating to ratetotal then update numofrates (numofrates + 1) then divide ratetotal by numofrates
then update rate with the new rate
Code: Select all
mysql_query("UPDATE foobar SET rate=".$rate." WHERE id='picid'");
Posted: Mon Nov 22, 2004 6:42 am
by John Cartwright
dull1554 wrote:have you tried to code anything? if you give us something we can help you from there
try this,
im assuming you have a database with all the info for each photo in the rows, add 3 new colums called ratetotal, numofrates, rate
then, make a rating script have it add the rating to ratetotal then update numofrates (numofrates + 1) then divide ratetotal by numofrates
then update rate with the new rate
Code: Select all
mysql_query("UPDATE foobar SET rate=".$rate." WHERE id='picid'");
I think you mean insert a new row. Updating the row would overwrite the previous users rating.
Posted: Mon Nov 22, 2004 7:32 am
by dull1554
nope i dont
if you read what i said i suggested tacking on three colums to each entry in the database, ratetotal, numofrates, rate.
when a person submits his rating you would do the following
Code: Select all
mysql_query("UPDATE foobar SET ratetotal=ratetotal+$rating");
mysql_query("UPDATE foobar SET numofrates=numofrates+1");
mysql_query("UPDATE foobar SET rate=ratetotal/numofrates");
but maybe my logic is flawed
have ratetotal be the total of all rates added together
have numofrates be just that, the number of rates
and have rate be ratetotal divided by numofrates
hope i cleared up my suggestion
Posted: Mon Nov 22, 2004 7:45 am
by John Cartwright
I guess its a matter if you see the glass half full or half empty.
Either way works.
Posted: Mon Nov 22, 2004 8:16 am
by timvw
and the OP should make sure these 3 queries get executed as 1 transaction... probably time to hit the manual of his favorite dbms

Posted: Mon Nov 22, 2004 8:43 am
by angelena
Wowww....thx for all those solutions ...
Am really sorry for din provide enough description on my prob.
Im planning to get the votes using radio button as input method.Im just using a single page for all this,so the form method will be using $PHP_SELF.
For my database,i haf a table by the name of pic_gallery.Each pic assigned an id and im using 2 field ( pic_votes & votes_count ) for this voting. Pic votes showing total votes the pic gets while votes count is how many user voted this pic.
Besides,to prevent a same user to vote multiple times for a same pic,i will get its ip to be inserted into a field named user_ip.So when a user vote for a pic,the validation will be on this user ip.
Emm...any info i left out? Huhh..i must be looks like in a mess with all my explanation....thx again for helping..im jz beginner in this

Posted: Mon Nov 22, 2004 9:47 am
by Maugrim_The_Reaper
Could throw all IPs into a single array, stored in serialised form on database (taking up just one field - text/blob) - then just use the PHP array functions to do your checks, pop-off old IPs if needed, etc...