Jump to content

PHP, 5 Star Rating System (Logic only)


keldorn

Recommended Posts

What the logic behind those 5 Star rating things you seee on youtube,

Is it just division? , like if someone votes  5, then store 5 in the DB, then if someone votes 2, divided 5 by 2, so you get 2.5 then round() it to 3, Then show 3 stars, is that all there is too it?

 

Edit; oh what if the rating is 3, now someone votes 5? You can't divided 3 by 5. :o

Link to comment
Share on other sites

What the logic behind those 5 Star rating things you seee on youtube,

Is it just division? , like if someone votes  5, then store 5 in the DB, then if someone votes 2, divided 5 by 2, so you get 2.5 then round() it to 3, Then show 3 stars, is that all there is too it?

 

What? How do you get a rating of two would display three stars? It's simply an average. You simply add up ALL the ratings and divide by the number (i.e. count) of ratings to get the average. Then round as needed.

 

Ex:

 

Ratings of 3, 4, 3, 2, 1, 5, 2

 

Sum = 20

Count = 7

 

Average = ( 20 / 7 ) = 2.86

Rounds to 3

Link to comment
Share on other sites

oh, Okay.

What would be the way to store the numbers in the row, serialize() it?

 

 

Edit: Nevermind, I would  normalize the database and  make a separate table for the ratings, Then create two indexs called "Count" and "votes", and store each number there rather then storing all the votes like 1,5,8,4,2,1

 

So you could have

 

id+Vote+Count+
1   20       5
2   40       9
3   55       12

 

Then just increment them when needed, and divided when needed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.