rating function in php

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
bhanu
Forum Commoner
Posts: 46
Joined: Thu Nov 05, 2009 4:25 am

rating function in php

Post by bhanu »

hi ,

how to code 5 start rating using php and mysql?

login member can only rate for items. one user can only rate item , one time only. we have to display total rating value in 5 starts.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: rating function in php

Post by Jonah Bron »

Make a database that looks something like this:

Code: Select all

 
_____________________________
| ID | Rating | UserID | RatedItem |
|1   | 4        | 97284 | 89489     |
|2   | 2        | 3928   | 1048       |
|3   | 5        | 10094 | 183         |
 
Rating, is the rating the user provided. UserID is the identity of the user that provided the rating. RatedItem, is the object that the user rated.

If you want to prevent the user from rating an item more than once, just check for an entry that has the user's ID, and the RatedItem ID.
Post Reply