rating star

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
abhikerl
Forum Newbie
Posts: 9
Joined: Wed Jun 04, 2008 2:07 am
Location: Mauritius

rating star

Post by abhikerl »

Does anyone knows how to do a rating system. In fact, I have already build it but I don't know how to merge it with the articles that have to rated. Each article should have a unique rate. It's like on youtube. If any one knows how to do it or can give a few advice. I'll be grateful.thanks in advance.

http://www.islandinfo.mu
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: rating star

Post by s.dot »

You need a database table with the article_id, total_votes, total_points.

Increment total_votes each time a vote is cast for that article, increment total_points by the rating the article received.

Do some math to get the rating. :)

You could do more and add in user ids or usernames to ensure each user only votes once.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: rating star

Post by superdezign »

I'm actually in the middle of implementing this for my own website at the moment. ^_^
After setting up the database the way that ~scottayy has shown:

Code: Select all

$rating = 0;
$decimalPlaces = 2;
if ($data->totalVotes != 0) {
  $rating = number_format($data->totalPoints / $data->totalVotes, $decimalPlaces);
}
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: rating star

Post by califdon »

abhikerl wrote:Does anyone knows how to do a rating system. In fact, I have already build it but I don't know how to merge it with the articles that have to rated. Each article should have a unique rate. It's like on youtube. If any one knows how to do it or can give a few advice. I'll be grateful.thanks in advance.

http://www.islandinfo.mu
I agree with the other 2 responders, but since you included the word "star" in your Subject, I'm assuming you are interested in the row of stars with some in gold, or something, as the display. Take a look at my site http://poatree.info and click on the Go To The Poems button. Is this what you're after? If it is, I'll be glad to send you the code for maintaining and displaying the ratings.
Post Reply