Given a database table with the following fields:
- total_votes: The total number of votes cast on this item/row
- average_value: The average voting value (i.e. 3.6 with 5 being the max)
- total_value: The sum of all the vote values (i.e. 3 votes of 4 will result in 12)
I was simply using a SELECT to grab the rows and the ORDER BY to sort them by their average value but then I ran into the issue of a good row with 10 votes averaging 4.9 getting outranked by a brand new row with only 1 vote of 5 outranking it.
After some research, I discovered that the most popular method of sorting rated items is to use a bayesian average.
br = ( (avg_num_votes * avg_rating) + (this_num_votes * this_rating) ) / (avg_num_votes + this_num_votes)
However, I'm having difficulty creating a query that pulls these rows and sorts them using this average as I'm a novice at creating anything advanced in terms of mySQL queries.
What I'm looking for is:
$results = mysql_query("INSERT ANSWER HERE");
Where INSERT ANSWER HERE
is the answer you provide me with and $results
provides these items sorted in by their Bayesian Average.
For more information about the Bayesian Average, I checked out: http://www.thebroth.com/blog/118/bayesian-rating