Working out a rating

Discussion in 'PHP' started by adamjblakey, Dec 16, 2010.

  1. #1
    Hi,

    I have a system in place where users can rate a comment 1 to 5 and that is entered into the database as 1, 2, 3, 4 or 5 which is fine but i want to display the rating on another page.

    I have 6 images for 0 rating up to 5 star the images are name 0star.png etc

    How would i work out which image to show based on all the submissions to the database?

    Cheers,
    Adam
     
    adamjblakey, Dec 16, 2010 IP
  2. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    You could get the average rating with "SELECT AVG(rating_field_name) FROM table_name WHERE ...", and select the star image to display based on the result.
     
    rainborick, Dec 16, 2010 IP
  3. goodmast3r

    goodmast3r Active Member

    Messages:
    1,220
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #3
    And probably use ceil function to make the value as integer.
     
    goodmast3r, Dec 16, 2010 IP
  4. lebspy

    lebspy Guest

    Messages:
    123
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    just google for a done script there are 100s for free
     
    lebspy, Dec 16, 2010 IP