Thx in advance ya
Building a rating system
Moderator: General Moderators
Building a rating system
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
Thx in advance ya
- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
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
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'");- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I think you mean insert a new row. Updating the row would overwrite the previous users rating.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 rateCode: Select all
mysql_query("UPDATE foobar SET rate=".$rate." WHERE id='picid'");
- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
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
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
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");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
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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
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
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland