Jump to content

[SOLVED] Timeout Issues


rhoffer21

Recommended Posts

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.

Link to comment
Share on other sites

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));
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.