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? Quote Link to comment Share on other sites More sharing options...
dadamssg Posted August 27, 2009 Share Posted August 27, 2009 yes Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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; ?> Quote Link to comment 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.