keldorn Posted November 26, 2009 Share Posted November 26, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/182971-php-5-star-rating-system-logic-only/ Share on other sites More sharing options...
Psycho Posted November 26, 2009 Share Posted November 26, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/182971-php-5-star-rating-system-logic-only/#findComment-965748 Share on other sites More sharing options...
keldorn Posted November 26, 2009 Author Share Posted November 26, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/182971-php-5-star-rating-system-logic-only/#findComment-965754 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.