play_ Posted August 27, 2009 Share Posted August 27, 2009 It's not code i need help with, but on the math behind it. Say i have a 5 star rating system for blog entries. I would store in the database.. table: ratings ratingID | userID | entryID | rating | ------------+--------------+------------+----------------+ 1 | 43 | 3 | 5 | Something like that. Now from here i'm suck. Say i go to a blog entry's page...how will i know how many stars to "light up" based on the database info? is it based on the average? Link to comment https://forums.phpfreaks.com/topic/172080-solved-5-star-rating-system/ Share on other sites More sharing options...
dadamssg Posted August 27, 2009 Share Posted August 27, 2009 yes Link to comment https://forums.phpfreaks.com/topic/172080-solved-5-star-rating-system/#findComment-907300 Share on other sites More sharing options...
play_ Posted August 27, 2009 Author Share Posted August 27, 2009 but once i find the average, how do i know how many stars to light up based on it? Link to comment https://forums.phpfreaks.com/topic/172080-solved-5-star-rating-system/#findComment-907305 Share on other sites More sharing options...
Garethp Posted August 27, 2009 Share Posted August 27, 2009 Well, if the average is three, light up three stars. If the average is four, light up four stars Link to comment https://forums.phpfreaks.com/topic/172080-solved-5-star-rating-system/#findComment-907306 Share on other sites More sharing options...
play_ Posted August 27, 2009 Author Share Posted August 27, 2009 Alright thanks. i guess something like this will suffice <?php $ratings = array( 1, 4, 3, 2, 2, 1, 5, 3 ,4 ,4 ,4 ,3 ,5, 2, 3, 1, 5, 5, 5 ,5 ,5 ,5 ,5 ,5 ,5); $sum = array_sum($ratings); $count = count($ratings); echo $sum / $count; ?> Link to comment https://forums.phpfreaks.com/topic/172080-solved-5-star-rating-system/#findComment-907317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.