SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Easy Way To Store & Process Ratings

    I've only just read through kevs book (which I would recmomend highly) so I'm pretty new to all this. I'm making a page where users can rate individual mp3 samples - samples will be ranked by rating (highest at the top of the page)

    Essentially I will have to have a "rated" collumn in my table and have the results sorted by "rated" - the only issue I have is how to store and calculate the rating collumn.

    I want to have "mean average" ratings, and the only way I can think of is to have a "number of times rated" and "total of all ratings" then divide these collumns to get the value for rating.

    Is that the best way of doing it?

    thanks,
    Mike

  2. #2
    What's HTML?
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    1,701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't know if this is the best way, but here's how I do it.

    My table has two extra fields, Rating and Votes. Rating has the total rating of a given object. For example, if someone voted a 10 and another voted a 5, Rating would contain 15. Votes has the total number of votes, in this example, 2.

    When I want to know the rating of something, I run a simple query:
    PHP Code:
    $result mysql_query("SELECT Rating, Votes FROM table WHERE id=$id"); 
    Then I divide the Rating by the Votes and voila! I have the average rating of the object.
    Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
    Get your website started for less than $20! Click Here

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect, that looks like it will work great! Much appreciated


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •