
December 13th, 2004
04:04 AM
Neverside Newbie
Status: Offline!
The math behind rating scripts
Hey,
Maths obviously isnt my strong point and i need some help in making a simple rating script, well i need to know the basics.
For example lets say i have an option of 1 - 5, a user can select a rating. Now this is where i get stuck.
The rating inputted into the database has to be between 1 & 5. lets say these are the values
<?php
$current_rating = 3; // the rating from the database
$submitted_rating = 5; // submited by the user
$total_rates = 23; // the total amount of votes taken from the db
//This is the thing i cant get my damn head around
$the_equasion = ?;
?>
So i hope i made it clear, anyone with any help would be apprechiated.
Thanks
Code
___________________
evolvedbb

December 13th, 2004
04:11 AM
whoa, wtf?
Status: Offline!
Total rating number/number of times rated.
___________________
Fomerly known as lasnaranjas. Holler.


December 13th, 2004
04:15 AM
Neverside Newbie
Status: Offline!
so that would be:
<?php
$new_rating = $current_rating / $total_rates;
?>
but it gives the answer:
0.115625
where i want the answer to be between 1 and 5.
Correct me if im wrong (im real bad at things like this)
___________________
evolvedbb

December 13th, 2004
04:29 AM
whoa, wtf?
Status: Offline!
Originally posted by Code
so that would be:
<?php
$new_rating = $current_rating / $total_rates;
?>
but it gives the answer:
0.115625
where i want the answer to be between 1 and 5.
Correct me if im wrong (im real bad at things like this)
say a user has n votes
vote_a = 3
vote_b = 5
vote_c =1;
in this case, n would be three
You'd want that to be
(vote_a + vote_b + vote_c)/ n
___________________
Fomerly known as lasnaranjas. Holler.


December 13th, 2004
04:45 AM
Neverside Newbie
Status: Offline!
its clicked in my head now, i understand how to do it 
___________________
evolvedbb

December 13th, 2004
06:03 AM
Neversidian
Status: Offline!
this is kind of scary
___________________
Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

December 13th, 2004
06:52 AM
Originally posted by Code
so that would be:
<?php
$new_rating = $current_rating / $total_rates;
?>
but it gives the answer:
0.115625
where i want the answer to be between 1 and 5.
Correct me if im wrong (im real bad at things like this)
wouldn;t it be...
[php]
$current_rating = ($current_rating + $new_rating) / $total_rates;
[php]
so it adds the new rating first then divids by the total...

December 13th, 2004
08:47 AM
whoa, wtf?
Status: Offline!
[QUOTE]Originally posted by Natural
[B]wouldn;t it be...
[php]
$current_rating = ($current_rating + $new_rating) / $total_rates;
[php]
so it adds the new rating first then divids by the total... [/B][/QUOTE]
no you'd be averaging on an averge.
___________________
Fomerly known as lasnaranjas. Holler.


December 16th, 2004
01:56 AM
overall Funny Guy
Status: Offline!
<?php
$new_rating = (($current_rating * $total_rates) + $submitted_rating) / $total_rates + 1;
$new_total = $total_rates + 1;
?>
___________________
"I find it kinda funny, I find it kinda sad,
The dreams in wich I'm dying are the best i've ever had"