Alffallen Posted April 6, 2007 Share Posted April 6, 2007 Okay so working on a script for my game and I'm getting a Fatal error: Maximum execution time of 30 seconds exceeded in c:\path\to\file\removed.php on line 59 However the the script does seam to work up to the point of updating at least one loop run. Noted in the fact that my hitpoints for those two id's are being updated each time i run the script. However this line 59 is throwing the maximum execution error. NOTE: Line 63 is prolly suffering the same problem as they are doing the same thing for the two diffrent users. $updatehp2 = mysql_query($updatehp, $thegame) or die( "Could not update player 1 hp"); Just as an idea. Imagine that each player has 1000 hitpoints and 100 strength. This script should be facing the two against eachother in rounds of random dmg. random 0-100. So in theory this script should loop roughly 10-35 times at max with my test info. So I'm not sure why I'm getting a maxed out query when the loop itself is pretty simple. The total script run time should be almost instant. Here is the code in full. <?php $username = fight("2", "4"); echo $username; function fight($attacker, $defender){ require('../Connections/thegame.php'); // Aquire attacking player info from passed arguement to build query string. $attacking_playerQuery = "Select * From users where id='$attacker'"; // Aquire defending player info from passed arguement to build query string. $defending_playerQuery = "Select * From users where id='$defender'"; //Select the database for query. mysql_select_db($database_thegame, $thegame); //query the attackers statistics. $row_attacking_playerQuery = mysql_query($attacking_playerQuery, $thegame) or die("could not load attacker."); //query the defenders statistics. $row_defending_playerQuery = mysql_query($defending_playerQuery, $thegame) or die("could not load defender."); //Build array info of the attacker. $array_attacking_playerQuery = mysql_fetch_assoc($row_attacking_playerQuery); //Build array info of the defender. $array_defending_playerQuery = mysql_fetch_assoc($row_defending_playerQuery); //Set both attacker and defender location values for comparison $attackerLocation = $array_attacking_playerQuery['location']; $defenderLocation = $array_defending_playerQuery['location']; #If both characters are in the same location if ($attackerLocation == $defenderLocation) { //set a variable to attacker and defenders current hp $play1hp= $array_attacking_playerQuery['currentHp']; $play2hp= $array_defending_playerQuery['currentHp']; #if both characters are above 0 hp while($play1hp>0 and $play2hp>0){ //Redefining the current hp for each loop $play1hp= $array_attacking_playerQuery['currentHp']; $play2hp= $array_defending_playerQuery['currentHp']; //Get the strength of both characters for use in a random variable. $player1dmg = $array_attacking_playerQuery['currentStr']; $player2dmg = $array_defending_playerQuery['currentStr']; //Create random dmg numbers based off of the users strength attribute. $play1rand = rand(0,$player1dmg); $play2rand =rand(0,$player2dmg); //Subtract the damage done from the current hp of each player $newply1hp = $play1hp - $play2rand; $newply2hp = $play2hp - $play1rand; //set variables to the characters names for use in the combat text. $play1name = $array_attacking_playerQuery['characterName']; $play2name = $array_defending_playerQuery['characterName']; //Build the player 1 update string $updatehp ="update users set currentHp=$newply1hp where id='$attacker'"; //update from that string $updatehp2 = mysql_query($updatehp, $thegame) or die( "Could not update player 1 hp"); //build the player 2 update string $update2hp ="update users set currentHp=$newply2hp where id='$defender'"; //update from that string $update2hp2 = mysql_query($update2hp, $thegame) or die( "Could not update player 2 hp"); #Create the combat text into the result string to pass back to the call posistion. $result_string = "<Br>You hit " . $play1name . " for " . $play1rand . " hitpoints.<br> You were hit for " . $play2rand. " hitpoints by " . $play2name . ".<br> You now have " . $newply1hp. " hitpoints.<br>"; } } #Error users not in same location Else {echo "You cannot attack a player in another location<br>"; } #Report the result back from the function. return $result_string; } ?> Link to comment https://forums.phpfreaks.com/topic/45829-a-query-problem/ Share on other sites More sharing options...
trq Posted April 6, 2007 Share Posted April 6, 2007 Man, your going to get real sick of typing by the time you finish writing any decent sized application. The length of those variable names is just ridiculous. Also, you have absolutely no error handling in place. The general syntax for a SELECT query should be something like... <?php if ($result = mysql_query($sql)) { // where $sql holds your query if (mysql_num_rows($result)) { // $result is now safe to use. while ($row = mysql_fetch_assoc($result)) { print_r($row); } } } ?> Link to comment https://forums.phpfreaks.com/topic/45829-a-query-problem/#findComment-222679 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.