Jump to content

[SOLVED] php rating system using mysql


jokerbla

Recommended Posts

Hi, this isn't really a mysql matter but it's the most appropriate section to post in.

 

I'm trying to make a rate system script in php and I'm using a database to store the voters and the average so far. So each time someone makes a new vote, average must be recalculated and voters is increased by one.

 

I'm having trouble with the maths, I've been over this for like 4 hours, and I'm not sure what the problem is.

 

newaverage = (average / voters + newvote) / (voters + 1)

 

.. and then I update the database and print the new average, but it doesn't work right. What's wrong with it?

Link to comment
https://forums.phpfreaks.com/topic/176378-solved-php-rating-system-using-mysql/
Share on other sites

might it be something else I did wrong?

$sgvote = mysql_query("SELECT * FROM vote") or die(mysql_error());
while($ratings = mysql_fetch_array( $sgvote ))
{
$voters = $ratings["voters"];
$average = $ratings["average"];
}

$newaverage = ($average / $voters + $choice) / ($voters+1);
$voters = $voters + 1;

$update = mysql_query("UPDATE vote SET voters=$voters, average=$newaverage");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.