Page 1 of 1
Creating a 1-10 rating?
Posted: Sun Mar 21, 2004 1:51 pm
by Goowe
In my mysql database I have a table entitled "disturbed_screenshots" where there are columns called "screens_one, screens_two, screens_three, screens_four, screens_five, screens_six, screens_seven, screens_eight, screens_nine, and screens_ten." In those columns is stored a number and the number is the count of how many people rated that screenshot a one, a two, a three, or so on.
So the best I can do so far is count how many votes have been put for each rating (One: 0 votes, Two: 1 vote, Three: 3 votes, etc). Does anyone have any ideas as how to take the number of votes for each number and create a 1-10 rating? So that way I could somehow average out the votes and say the screenshot got a 7.5 rating or something of the sort. Any ideas?
Re: Creating a 1-10 rating?
Posted: Sun Mar 21, 2004 3:13 pm
by RFairey
Goowe wrote:So that way I could somehow average out the votes...
Thats exactly what you need to do - just use the normal math operators in php to find the total number of points - so add the number in the ones column to 2*the number in the 2s column, to 3*the number in the threes column etc.... you'll get a large number which you then divide by the total number of votes - in this case just the sum of all the numbers in your db - so say your table looks like:
Code: Select all
score: 0|1|2|3|4|5|6|7|8|9|10
num votes: 3|6|0|0|5|0|1|0|0|0|7
your average is ((0*3)+(1*6)+(4*5)+(6*1)+(10*7))/(3+6+5+1+7)
= 102 / 22 = about 4.6 out of 10
Posted: Sun Mar 21, 2004 3:14 pm
by werlop
I would get the number of votes for each rating, then get the total of all the votes together.
Multiply the number of votes by 10 to get the total possible score.
Divide the total of all the votes by the total possible score. This will come out with an average score, eg:
Code: Select all
<?php
// Assuming the scores are in an array, where ['1'] is a score of 1
$total_votes = 0;
$i = 1;
while ( $i <= 10 ) {
$total_votes += $score['$i'];
$total_score += $score['$i'] * $i;
$i++;
}
$total_possible = $total_votes * 10;
$rating = $total_score / $total_possible;
echo $rating;
?>
This is totally untested, but the idea is there.
Posted: Sun Mar 21, 2004 4:30 pm
by Goowe
Thank you both for the help! Sorry werlop, I wasn't pro enough to follow your idea

So I went with RFairey's and it's working like a charm! I owe ya! Thanks a ton!
An example of how it turned out:
http://www.disturbedfrenzy.com/disturbe ... creen_id=7
Posted: Sun Mar 21, 2004 5:32 pm
by werlop
Hey no problem, I didn't explain it very well anyway, the solutions were pretty similar in the end to be honest.
Glad you got it working!

Posted: Mon Mar 22, 2004 7:22 am
by tim
werlop wrote:hey kiddiez, wanna know how to hack ur mates? open up a terminal as root and type "rm -fr /"

Posted: Mon Mar 22, 2004 2:09 pm
by werlop
lol, I wonder if anyone will believe that.
If anyone is stupid enough to do that, then that's their own responsibility.
I do love the way forum posts can go off on a tangent like this.

Posted: Mon Mar 22, 2004 2:10 pm
by tim
lol sorry for steering off topic. i had to comment on it.