Hi. Basically, this is a user submission script that comes from one of five radio buttons on the page before. The /input form looks like this:
<form method="POST" action="pratingsystem.php">
<?php
echo '<input type="hidden" name="jokeId" value="$id">'; //$id comes from what's earlier on the page, a dispay script
?>
<input type="radio" value="5" checked name="rating">Excellent
<input type="radio" name="rating" value="4">Good
<input type="radio" name="rating" value="3">OK
<input type="radio" name="rating" value="2">Not-so-good
<input type="radio" name="rating" value="1">Sucks</p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>
The submission/proccessing script looks like this:
<?php
$db="mysql_connect('localhost', '', '')"
mysql_select_db(db_thawowi_2, $db)"
$number=0;
$number="SELECT number FROM table WHERE id='$jokeId'"; //I need the id part
$number=$number+1;
$query="UPDATE table SET number='$number' WHERE id='$jokeId'";
$result="mysql_query($query, $db); \inserted the new total
$total=0;
$total="SELECT total FROM table WHERE id='$jokeID'";
$total='$total'+'$rating';
$secondquery="UPDATE table SET total='$total' WHERE id='$jokeID'";
$secondresult="mysql_query($secondquery, $db);
$average="$total/$number"; //total is the number I get after adding all user submissions together, this is (if I remeber math correctly) the formula for finding the arithmetic mean
$finalquery="UPDATE table SET average='$average'";
$finalresult="mysql_query($finalquery, $db)";
echo "some success message";
?>
Basically, what the above code does is it finds the average of all the user submissions, and records that in a database. $total is all user submissions added together (one person votes 3, anothr person votes 5, $total would be 8 etc.) $number is the total number of user submissions (one person votes 3, anothr person votes 5, $number would be 2 because 2 people voted). $total, $number and $average are IN THE DATABASE and I update the database with the new numbers for future reference (i.e. finding out the average after the next person votes).
My question is, will all this work in order? (update $number first, $total second, and $average third). If not, is there a way to make without writing 3 separate codes?
Thanks.