Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Math for a php code :)

1. ## 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. Originally Posted by dsylebee
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
•