Forum Moderators: coopster

Message Too Old, No Replies

Getting empty table row above

         

pixeldiver

11:18 pm on Aug 25, 2009 (gmt 0)

10+ Year Member



Hi guys,
I am trying to fetch data and display it in a table, which basically works fine. My only problem is, I am getting an empty table row displayed above the actual data output. The only item which is displayed in that row is the checkbox, which I don't want to have there.
I think there is something wrong with the do while loop. Any ideas what could cause the empty table row?

Here is my code:

$query = "(SELECT id, prod_code, air_quantity, neck_size, area, neck_velocity, total_pressure, static_pressure, noise_levels, air_throw FROM dco_ls WHERE air_quantity < $air_quantity ORDER BY id DESC LIMIT 2) UNION (SELECT id, prod_code, air_quantity, neck_size, area, neck_velocity, total_pressure, static_pressure, noise_levels, air_throw FROM dco_ls WHERE air_quantity >= $air_quantity ORDER BY id ASC LIMIT 2) ORDER BY air_quantity ASC ";
$result = mysql_query($query, $dragon) or die(mysql_error());
$totalRows = mysql_num_rows($result);
do { ?>


<table width="950" border="0" cellpadding="0" cellspacing="0" id="table_selection_results">
<tr><td width="80" align="left" valign="middle"><?php echo $row ['prod_code']; ?></td>
<td width="80" align="left" valign="middle"><?php echo $row ['neck_size']; ?></td>
<td width="80" align="left" valign="middle"><?php echo $row ['area']; ?></td>
<td width="100" align="left" valign="middle"><?php echo $row ['neck_velocity']; ?></td>
<td width="80" align="left" valign="middle"><?php echo $row ['total_pressure']; ?></td>
<td width="80" align="left" valign="middle"><?php echo $row ['static_pressure']; ?></td>
<td width="100" align="left" valign="middle"><?php echo $row ['air_quantity']; ?></td>
<td width="110" align="left" valign="middle"><?php echo $row ['noise_levels']; ?></td>
<td width="100" align="left" valign="middle"><?php echo $row ['air_throw']; ?></td>
<td width="80" align="left" valign="middle"><input name="product_checked" type="checkbox" value="prod_checked" /></td></tr>
</table>

<?php } while ($row = mysql_fetch_assoc($result)); ?>

eelixduppy

11:59 pm on Aug 25, 2009 (gmt 0)



This is because you are using a do-while loop, which is not appropriate for this situation. By definition, a do-while loop executes the loop body BEFORE it checks the while condition on the first iteration. So for this case, you are printing out a table before you set the
$row
variable to contain the data. To fix this you are going to want to use just a regular while loop, such as the following:

while ($row = mysql_fetch_assoc($result)) {
?>

<table width="950" border="0" cellpadding="0" cellspacing="0" id="table_selection_results">
<tr><td width="80" align="left" valign="middle"><?php echo $row ['prod_code']; ?></td>
<td width="80" align="left" valign="middle"><?php echo $row ['neck_size']; ?></td>
<td width="80" align="left" valign="middle"><?php echo $row ['area']; ?></td>
<td width="100" align="left" valign="middle"><?php echo $row ['neck_velocity']; ?></td>
<td width="80" align="left" valign="middle"><?php echo $row ['total_pressure']; ?></td>
<td width="80" align="left" valign="middle"><?php echo $row ['static_pressure']; ?></td>
<td width="100" align="left" valign="middle"><?php echo $row ['air_quantity']; ?></td>
<td width="110" align="left" valign="middle"><?php echo $row ['noise_levels']; ?></td>
<td width="100" align="left" valign="middle"><?php echo $row ['air_throw']; ?></td>
<td width="80" align="left" valign="middle"><input name="product_checked" type="checkbox" value="prod_checked" /></td></tr>
</table>

<?php
}

Good luck. :)

pixeldiver

2:35 am on Aug 26, 2009 (gmt 0)

10+ Year Member



Changed it, updated xampp, had a look, just beautiful!
Thanx a lot.