Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Math for a php code :)
05-27-2009, 03:43 AM #1
- Join Date
- Oct 2008
- 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
05-27-2009, 01:57 PM #2
- Join Date
- Sep 2005
- Orlando, FL
- Thanked 40 Times in 40 Posts
Which doesn't really do anything for you.Code:overallAvg * votes / 10 * votes = x / 1000 overallAvg / 10 = x / 1000 overallAvg = x / 100
To find an average score, you do:
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:(score1 + score2 + ... + scoren) / n = avgScore Where n equals total number of votes
-ShaneCode:SELECT (totalScore / totalVotes) AS overallAvg FROM table ORDER BY overallAvg DESC LIMIT 100;