Why is this an infinite loop?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Why is this an infinite loop?

Post by tristanlee85 »

Code: Select all

<?
//
//Start of the report
//

if (isset($_POST['get'])) { //START POST IF

$getdate = $_POST['date'];
$query="SELECT * FROM misloads where date = '$getdate'";
$result=mysql_query($query);
$num=mysql_numrows($result);

if ($num==0)
{
	echo "No results in the database.";
}
else
{
$count=0;
while ($count < $num) {

$employee=mysql_result($result,$count,"loader");
$door_number=mysql_result($result,$count,"door_num");
$misloads=mysql_result($result,$count,"misload_zip");
//$date=mysql_result($result,$count,"date");

//Get door name for door number
$door_name="SELECT door_name FROM load_doors WHERE door_num = '$door_number' && loader = '$employee'";
$door_name=mysql_query($door_name);
$door_name=mysql_fetch_row($door_name);

echo "<table border='0' width='100%' align='center'>
	<tr>
		<td align='center' colspan='4'>
		<u><b>DAILY PERFORMANCE RESULTS</b></u>
		</td>
	</tr>
	<tr>
	</tr>
	<tr>
		<td align='left' colspan='4'>
		<b>Employee:</b> $employee
		</td>
	</tr>
	<tr>
		<td align='left' colspan='4'>
		<b>Date:</b> $getdate
		</td>
	</tr>
	<tr>
	</tr>
	<tr>
		<td align='left' colspan='4'>
		<b>MISLOAD STATISTICS</b><br><hr>
		</td>
	</tr>
	<tr>
		<td align='left'>
		$door_name[0] ($door_number)
		</td>
		<td align='left'>
		$misloads
		</td>
	</tr>
	<tr>
	</tr>
	<tr>
		<td align='left' colspan='4'>
		<b>LOAD FACTOR STATISTICS</b><br><hr>
		</td>
	</tr>
	<tr>
		<td align='left' width='25%'>
		[door_name] ([door_num])
		</td>
		<td align='left' width='25%'>
		Total packages: [total_packages]
		</td>
		<td align='left' width='25%'>
		Trailers filled: [trailers_filled]
		</td>
		<td width='25%'>
		</td>
	</tr>
	<tr>
		<td colspan='4'><hr></td>
	</tr>
	<tr>
		<td width='25%'>
		</td>
		<td width='25%'>
		</td>
		<td width='25%'>
		<b>Total misloads</b>
		</td>
		<td width='25%'>
		<b>% of goal</b>
		</td>
	</tr>
	<tr>
		<td width='25%'>
		</td>
		<td width='25%'>
		</td>
		<td width='25%'>
		$misloads		</td>
		<td width='25%'>
		[calculated_of_goal]		</td>
	</tr>
	<tr>
	</tr>
	<tr>
		<td width='25%'>
		</td>
		<td width='25%'>
		</td>
		<td width='25%'>
		<b>Load Factor</b>
		</td>
		<td width='25%'>
		<b>% of goal</b>
		</td>
	</tr>
	<tr>
		<td width='25%'>
		</td>
		<td width='25%'>
		</td>
		<td width='25%'>
		[load_factor]		</td>
		<td width='25%'>
		[calculated_of_goal]		</td>
	</tr>
</table>
"; //end ECHO
}
$count++;
}
}
?>
I copied this code from one of my other sites that works perfectly. It's basically reading everything from the database right, but it doesn't seem like $count is increasing since it keeps displaying the first row from the database everytime. Why isn't $count increasing? I've spent forever on this thing.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Your increment of $count is outside the while loop.
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

You've got to be kidding me. I spent forever looking for the reason. I guess I counted my brackets wrong compared to the old code. Thanks for the obvious. :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Better indentation habits would likely help in future problems of this nature.
Post Reply