Building a 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
angelena
Forum Commoner
Posts: 53
Joined: Mon Nov 22, 2004 4:10 am

Building a rating system

Post 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 :)
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

i would recomend looking at pre written scripts for ideas

hotscripts.com comes to mind
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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'");
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I guess its a matter if you see the glass half full or half empty.

Either way works.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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 ;)
angelena
Forum Commoner
Posts: 53
Joined: Mon Nov 22, 2004 4:10 am

Post 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 :)
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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...
Post Reply