Page 1 of 1

Why is this an infinite loop?

Posted: Sat Aug 19, 2006 11:41 pm
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.

Posted: Sat Aug 19, 2006 11:45 pm
by feyd
Your increment of $count is outside the while loop.

Posted: Sat Aug 19, 2006 11:47 pm
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. :)

Posted: Sat Aug 19, 2006 11:54 pm
by feyd
Better indentation habits would likely help in future problems of this nature.