Page 1 of 1

rating star

Posted: Wed Jun 11, 2008 4:29 am
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

Re: rating star

Posted: Wed Jun 11, 2008 4:57 am
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.

Re: rating star

Posted: Wed Jun 11, 2008 5:03 am
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);
}

Re: rating star

Posted: Wed Jun 11, 2008 1:31 pm
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.