rhoffer21 Posted November 30, 2008 Share Posted November 30, 2008 I just started learning PHP/MySQL today. I'm trying to design a website that will make the management of a baseball league I run a little easier. I have a few while loops in this script that I am writing and I keep getting a timeout error. Any tips to speed up the script would be great. Thanks, Ryan <?php set_time_limit(60); //includes the server configuration and opens the database include 'config.php'; include 'opendb.php'; //selects the table standings from our database $result = mysql_query('SELECT * FROM standings') or die(mysql_error()); //initializes the initial table echo "<table border='1' cellspacing='0' frame='box' spacing='0' padding='1'>"; //The following code displays the table headers with a red background and white text echo "<tr bgcolor='red'><th><b><center><font color='White' size='2'>Name</center></b></th> <th><b><center><font color='White' size='2'>W</center></b></th> <th><b><center><font color='White' size='2'>L</center></b></th> <th><b><center><font color='White'>PCT</center></b></th></tr>"; //this while loop will read all the data about the teams and arrange them the way I want it to while($row = mysql_fetch_array($result)) { //sets games equal to wins + losses $games = $row['wins'] + $row['losses']; //if the team has played any games this if statement sets winpercentage to the proper percentage //if not it sets winpercentage to 0 if ($games > 0) { $winpercentage = $row['wins'] / $games; } else { $winpercentage = 0; } //multiples winpercentage by 1000 for proper format $winpercentage*=1000; $standingcountertop = 1002; $standingcounterbottom = 1000; $standingcountertop = $standingcountertop-1; $standingcounterbottom = $standingcounterbottom-1; while ($standingcountertop > '-1'); { if ($winpercentage > $standingcounterbottom && $winpercentage <$standingcountertop) { //accesses the database and outputs team name wins and losses echo "<tr>"; echo "<td><font size='2'>"; echo $row['name'] . " </td>"; echo "<td><font size='2'>"; echo $row['wins'] . " </td>"; echo "<td><font size='2'>"; echo $row['losses'] . " </td>"; echo "<td><font size='2'>"; //these statements sets the decimal point for proper display if ($winpercentage == '0') { $winpercentage = '.000'; echo $winpercentage; } else if ($winpercentage == '1000') { $winpercentage = '1.000'; echo $winpercentage; } else { echo "."; echo number_format($winpercentage) . " </td>"; } } } }//End of while loop //ends the table echo "</table>"; //closes the databse for security include 'closedb.php'; ?> Edit ---- I'm not sure whether I overlooked some logic and this is stuck in an endless loop or if it is simply taking that long to run through the loops. Just looking for a few extra eyes to glance at it. Quote Link to comment Share on other sites More sharing options...
JADASDesigner Posted November 30, 2008 Share Posted November 30, 2008 Haven't delved into the script but remove your time linit line, also paste your config and opendb files. there may be an issue in one of them. feel free to edit out any sensitive info (like passwords...) Quote Link to comment Share on other sites More sharing options...
rhoffer21 Posted November 30, 2008 Author Share Posted November 30, 2008 I added the time limit thing because by default it is 30 seconds and i thought that maybe if it had a little more time it could finish, but it still timed out at 60 seconds, so that line is irrelevant anyway and i have already removed it. I have wamp installed so my config info is all localhost info and ill attach them below: <?php // This is config.php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $dbname = 'baseball'; ?> <?php // This is opendb.php $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); ?> <?php //this is closedb.php mysql_close(mysql_connect($conn)); ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2008 Share Posted November 30, 2008 Your while($standingcountertop > '-1'); loop is a forever loop because you are not doing anything to change the value of $standingcountertop inside of the loop. It just loops until the php execution time limit is reached. Quote Link to comment Share on other sites More sharing options...
rhoffer21 Posted November 30, 2008 Author Share Posted November 30, 2008 Ahhhhh, I figured it was something dumb like that. Going to fix the code right now and I'll let you know what happens. Thanks alot. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2008 Share Posted November 30, 2008 The semi-colon ; on the end of that line is a problem as well and should be removed. Quote Link to comment Share on other sites More sharing options...
rhoffer21 Posted November 30, 2008 Author Share Posted November 30, 2008 Those 2 problems were the cause. Thanks a bunch for looking at it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.