Looping through database results (rows) using a while loop, my main heading table row
is not inside the loop so displays once at the top of the output. I also have a third table row
containing subheadings, which because it is inside the loop repeats for every row in the output.
Is it possible to display the sub-headings table row only on the loop's first iteration and then
bypass it thereafter (perhaps using continue or break)?
$sql = "select * from uploads where cat_name = 'Leaflet'";
$result = $connection->query($sql) or die(mysqli_error($connection));
$numRows = $result->num_rows;
<table width="100%" cellspacing="0" cellpadding="0" class="text-decor" align="center">
<tr>
<th colspan="4" class="thead">Leaflets</th>
</tr>
<tr align="center" class="tbrow">
<td width="64">Type</td>
<td width="450">Title</td>
<td width="100">Size</td>
<td width="150"> Date</td>
</tr>
if ($numRows == 0) {
?>
<br /><br />
<font color="red"><p>No downloads found</p></font>
<?php
} else {
while($row = $result->fetch_assoc()) {
$bytes = $row['size'];
$date = $row['upload_date'];
$document_name = $row['document_name'];
$document_type = $row['document_type'];
$description = $row['description'];
?>
<tr align="left">
<td>
<td align="center"><?php echo $document_name; ?>
</td>
<td align="center">
<?php echo $newbytes; ?>
</td>
<td align="center">
<?php echo $date; ?></td>
</tr><tr><td colspan="4"><div class="desc_div">Description</div></td></tr> This row contains a sub-heading
<tr><td colspan="4" class="pad"><?php echo $description; ?></td></tr>
<tr><td colspan="4"> </td></tr>
<?php
}
?>
</table>