I have this:
[PHP] $siteid = $_POST[siteid];
$newrating = $_POST[rating];
$result = mysql_query("SELECT `rating`, `numvotes` FROM `reviews_site` WHERE `id` = $siteid");
while($rate=mysql_fetch_array($result)){
$curnumvotes = $rate[numvotes];
$currating = $rate[rating];
}
$curnumvotes++;
$newnumvotes = $curnumvotes;
$final1 = ($currating + $newrating); // add old and new
$final2 = ($final1/$newnumvotes); // get average
$final2 = number_format($final2, 2, '.', '');
$query = "UPDATE `reviews_site` SET `rating` = $final && `numvotes` = $newnumvotes WHERE `id` = $siteid";
$uresult = mysql_query($query);[/PHP]
$_POST[siteid] is equal to 2
$_POST[rating] is equal to any number from 0-5, depends in what is submitted at form.
This basically is supposed to take the original rating value, add it to the new submitted rating value and then divide it by the number of votes.
Ive echoed it all out step by step to see if its doing the calculations and it does but it wont update the database with the new values.
Any suggestions?
Comments
sebastianastill.co.uk - My Portfolio
...sorry
sebastianastill.co.uk - My Portfolio
The Royal Ram
1. what did mysql_query return?
2. add another line of code after this to check how many rows were affected...
I changed the query to:
$query = "UPDATE reviews_site SET rating='$final2', numvotes='$newnumvotes' WHERE id = '$siteid' ";
That was the problem, lol
Anyway you can see the script itself in action at http://www.devdreams.com/reviews - still being worked on though.
Thanks anyway
The Royal Ram
I think its because I had the layout of the query wrong. I had written it as if it was a SELECT query.
The Royal Ram