I recently began a project to make an automated rating system for a radio series’ episodes. The premise is that it should work similarly to the “Kittenwars” page. As a prelude to this, I’ve started to try to implement a test system that uses all the same parts that will be necessary for the final completed page.
Here’s essentially how it is (supposed) to work:
- PHP generates two psuedo-random numbers.
- PHP contacts the server and selects two random items from the “game” table on the “test” database. Their IDs correspond with the previously picked random numbers.
- PHP contacts the server and echos the previously selected random items’ “points” for the user.
- PHP generates two forms. Each one, when sent, contacts the server and updates two numbers in the “storage” table. The first number sent by each form is the “winning” ID, the second number is the “losing” ID.
- The user clicks on one of the forms mentioned in the previous step.
- Before any of the above code has technically happened yet, PHP connects to the server. It selects the two numbers from “storage”, and updates the rows that the numbers correspond to in the “game” table – thus completing the cycle (since the “game” table is the one the user intends to influence).
Unfortunately, I’ve encountered a hurdle in development. When the user clicks on the submit button, the numbers the forms send to the server are not the numbers that the user saw, but instead the next numbers – the ones that are generated after the user clicks on one of the forms. This problem actually came up earlier in development, so I added the “storage” table with the idea that I could store the numbers it was supposed to have in the server (before they get wiped out by the next php rand action), and call them up for use after the page has been refreshed, but this hasn’t helped me at all.
I’m sorry if this description of the problem doesn’t suffice; I’m willing to provide any information on the MySQL database that’s necessary, and/or pictures of any stage of the process that y’all may want.
Here’s the PHP code (sloppy as it is) below. I don’t have any prior experience, so I have to admit that most of this comes from combining and changing tutorial code fragments. Thanks in advance for any help anyone can give; I’m at a dead end right now.
[php] <?php
mysql_connect(“localhost”, “user”, “password”) or die(mysql_error());
echo “Initial connection to the server was successful!
”;
mysql_select_db(“test”) or die(mysql_error());
$result = mysql_query(“SELECT * FROM storage WHERE ID = ‘1’”);
$row = mysql_fetch_assoc($result);
$storage = $row[‘numbers’];
$result = mysql_query(“SELECT * FROM storage WHERE ID = ‘2’”);
$row = mysql_fetch_assoc($result);
$storage2 = $row[‘numbers’];
$result = mysql_query(“UPDATE game SET Points=points + 1 WHERE ID = ‘$storage’”);
$result = mysql_query(“UPDATE game SET Points=points - 1 WHERE ID = ‘$storage2’”);
?>
<?php
$result = mysql_query(“SELECT * FROM game WHERE ID = ‘$test’”);
while($row = mysql_fetch_assoc($result)){
echo “ID: “.$row[‘id’].”, Points:”.$row[‘points’]."
";
}
$result = mysql_query(“SELECT * FROM game WHERE ID = ‘$test2’”);
while($row = mysql_fetch_assoc($result)){
echo “ID: “.$row[‘id’].”, Points:”.$row[‘points’]."
";
}
?>
<?php echo '