Page 1 of 1
rating system problem
Posted: Sat Dec 27, 2003 7:53 am
by bytte
I have the next problem.
I have a cd review database. Registered people should be able to rate the reviewed cd's (values from 1 to 10). But how do I check to see if they have rated this cd already?
I think it has something to do with putting their username in the database record of the current cd?
Any help appreciated!
Posted: Sat Dec 27, 2003 8:17 am
by lazersam
Hi bytte
I would tag a field in the CD's database with the voters id and then search the row for the id whenever a new vote is made. That seems the simplest way to me, although it does mean ever growing bytes in the database.
Lawrence.
Posted: Sat Dec 27, 2003 8:20 am
by bytte
thanks. what type should my field then be?
Posted: Sat Dec 27, 2003 8:27 am
by lazersam
it depends on the type of your id.
It might be an idea to use just one field and keep adding ID's into it. That way it can grow and grow. Im not sure whether there is a limit to the length of a field.
Example (if IDs are int);
Name: Pink Floyd
IDs: 1, 34, 67, 543, 54,
The IDs field keeps being added to. You could then get the string and search through it looking for the ID.
Lawrence
Posted: Sat Dec 27, 2003 11:11 am
by DuFF
If many people vote on the CD's this could cause your database to become
much bigger. I would suggest just setting a cookie on the user's machine and this will stop most people from voting again although you can get around it. You can just save something like the ID or the name of the CD in the cookie and then check if that specific cookie is set before letting a user vote again.
More info on Cookies:
http://www.php.net/set_cookie
Posted: Sun Dec 28, 2003 6:00 am
by bytte
thanks!
Posted: Fri Jan 02, 2004 12:04 pm
by bytte
lazersam wrote:
The IDs field keeps being added to. You could then get the string and search through it looking for the ID.
Can you give me a code example of this?
Posted: Fri Jan 02, 2004 12:11 pm
by m3mn0n
I personally would make a new table called
cd_votes. Then within the table have
voteID,
userID,
cdID, and
timestamp for columns.
Then at the voting page, I would query the
cd_votes table for a vote with a cdID the same ID as the CD being viewed and the same userID as the current user viewing the page. If a match exists he/she has voted. If not then display a voting area, since this means they have not voted.
If it makes sense it's a good solution.

Posted: Fri Jan 02, 2004 1:21 pm
by d3ad1ysp0rk
Even after all that work, wouldn't a user just be able to register again (or more than twice) if they wanted to?
Cookies are probably your best solution..
Posted: Fri Jan 02, 2004 3:51 pm
by m3mn0n
This isn't the lottery, just a simple cd rating. I don't think people would be that determined to create a new account for that extra vote. heh
This ties the vote with their account rather than with their browser. If the user logs in with Mozilla insead of IE, they can revote. If the user deletes cookies, they can revote. If they use another computer, they can revote.
Not to disregard the usefulness of cookies in general, in this particular case I think they are a second resort to the above method.
Posted: Mon Jan 05, 2004 4:47 am
by bytte
Exactly for the reasons Sami mentioned, I think cookies aren't that useful here as an account-limited vote.
Thanks Sami for the idea as well. I think this is the best solution, i've got it working now.