rating system problem

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
bytte
Forum Commoner
Posts: 75
Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium

rating system problem

Post 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!
User avatar
lazersam
Forum Contributor
Posts: 105
Joined: Sat Nov 15, 2003 4:07 am
Location: Hertfordshire, UK

Post 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.
bytte
Forum Commoner
Posts: 75
Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium

Post by bytte »

thanks. what type should my field then be?
User avatar
lazersam
Forum Contributor
Posts: 105
Joined: Sat Nov 15, 2003 4:07 am
Location: Hertfordshire, UK

Post 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
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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
bytte
Forum Commoner
Posts: 75
Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium

Post by bytte »

thanks!
bytte
Forum Commoner
Posts: 75
Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium

Post 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?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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. :wink:
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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..
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
bytte
Forum Commoner
Posts: 75
Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium

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