Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2008
    Posts
    102
    Thanks
    28
    Thanked 4 Times in 4 Posts

    Math for a php code :)

    Ok well this is what i came up with and I wanted to know if its a good way to make a rating average to do top 100 ranks etc..

    so every different stuff that were voted all have a final average of x on 10 ( x/10 )

    so to make a top 10 of those i would need to make a general rating variable and store in my database to use the order by and desc etc..

    so what I came up with is


    (overallAvg * votes) / (10 * votes) = x / 1000

  • #2
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Quote Originally Posted by dsylebee View Post
    Ok well this is what i came up with and I wanted to know if its a good way to make a rating average to do top 100 ranks etc..

    so every different stuff that were voted all have a final average of x on 10 ( x/10 )

    so to make a top 10 of those i would need to make a general rating variable and store in my database to use the order by and desc etc..

    so what I came up with is


    (overallAvg * votes) / (10 * votes) = x / 1000
    Your formula simplifies to:
    Code:
    overallAvg * votes / 10 * votes = x / 1000
    overallAvg / 10 = x / 1000
    overallAvg = x / 100
    Which doesn't really do anything for you.

    To find an average score, you do:
    Code:
    (score1 + score2 + ... + scoren) / n = avgScore
    Where n equals total number of votes
    To store it, you would want to either store every vote with the score they gave it, or you would store the total score and total votes. You could then calculate the overall average as you pulled it out of the DB, especially with the 2nd option:
    Code:
    SELECT (totalScore / totalVotes) AS overallAvg
    FROM table
    ORDER BY overallAvg DESC
    LIMIT 100;
    -Shane


  •  

    Posting Permissions

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