Dear all experts

im now creating a rating system with php using mysql databse,
im facing the problem about how to calculate rating!, ex. i have totalscore and numofvotes table, which function that we can use to calculate rating like, 7.4, 4.5 something like that

thanks in advance

Recommended Answers

All 3 Replies

You are probably better off having a single table in your database that just contains the votes of each user on each item being rated. This way you can ensure that each voter can only vote once for something. In order to calculate the total score, number of votes and average rating, you can do this:

SELECT SUM(Votes), COUNT(Votes), AVG(Votes) FROM UserVotes
WHERE Item = Whatever

or something similar...

AVG(Votes) is exactly what you want......

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.