View Single Post
Old 07-14-2004, 04:38 AM   #4 (permalink)
Silvy
paranoid
 
Silvy's Avatar
 
Location: The Netherlands
In addition to the above suggestion, to create correct ratings, your DB will need at least another field: number_of_votes.

The field 'rating' should contain the sum of all votes received. The average is then easily calculated:
PHP Code:
$old_rating db_results['rating'];   //current average rating
$old_votes db_results['number_of_votes'];  //number of people that have voted until now.
$current_rating user_input['rating'];   //the rating the current user has entered
$new_votes $old_votes+1;   //the number of votes after the new rating.

$new_rating $old_rating $current_rating;
// you can now insert $new_rating and $new_votes into the DB.

And you can use: $average $new_rating $new_votes to display the current standings
Now this will result in large numbers in your table (the total points awarded will get big real quick). If that's not what you want (for ordering the table perhaps) you can also store the average into the table. But you'll need to calculate the total points awarded whenever a new vote is added....
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. "
- Murphy MacManus (Boondock Saints)

Last edited by Silvy; 07-14-2004 at 04:41 AM..
Silvy is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38