Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

140 users online



The math behind rating scripts

The math behind rating scripts

Currently viewing this thread: 1 (0 members and 1 guests)


Page 1 out of 2
cannotbeused2

cannotbeused2

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:

<?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

phpmonkey

phpmonkey

whoa, wtf?
Status: Offline!

Total rating number/number of times rated.

___________________

Fomerly known as lasnaranjas. Holler.
http://card.mygamercard.net/gelsig/blackdood.png

cannotbeused2

cannotbeused2

Neverside Newbie
Status: Offline!

so that would be:

PHP:

<?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

phpmonkey

phpmonkey

whoa, wtf?
Status: Offline!
Quote:

Originally posted by Code
so that would be:

PHP:

<?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.
http://card.mygamercard.net/gelsig/blackdood.png

cannotbeused2

cannotbeused2

Neverside Newbie
Status: Offline!

hmmm confusing :S

___________________

evolvedbb

cannotbeused2

cannotbeused2

Neverside Newbie
Status: Offline!

its clicked in my head now, i understand how to do it Grin

___________________

evolvedbb

BigToach

BigToach

Neversidian
Status: Offline!

this is kind of scary

___________________

Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

Natural

Natural

Status: Offline!
Quote:

Originally posted by Code
so that would be:

PHP:

<?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...

phpmonkey

phpmonkey

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.
http://card.mygamercard.net/gelsig/blackdood.png

Unini

Unini

overall Funny Guy
Status: Offline!
PHP:

<?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"

Page 1 out of 2
Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0096 seconds.