Remove '<th>' during loop

I’ll try to explain this as best as I can:

I have a table in a loop that displays results of runners organized by age ($row_getResults[‘heading’]) then organized by whether they ran the ‘1 Mile’ ($row_getResults[‘mile’]) or the ‘8K’.

The table has ‘<th>’ headers of:
Place
Name
City
Bib No.
Age
Overall
Time
Pace

within each ‘<th>’ cell in a row below the heading ($row_getResults[‘heading’]). The queried content displays correctly and is organized just fine. What I need help is to not have the ‘<th>’ repeat if the content falls under the same $row_getResults[‘heading’]. I only want one ‘<th>’ row per table of results.

The following results are displayed with one table:
Place Name City Bib No. Age Overall Time Pace
1 Scott Mac Sunnyvale, CA 12 9 12 3:00.3 3:00/M
Place Name City Bib No. Age Overall Time Pace
2 Jerry Marc Los Angeles, CA 11 12 9 4:12.1 4:12/M

Imagine how this looks with 100 records. EEK!

The ‘<th>’ row is static.

<?php do { ?>
<?php if ($row_getResults['mile'] !=$mile) { echo "<h2 style='font-size: 18px; text-align: center;'>".$row_getResults['mile']."</h2>"; $mile = $row_getResults['mile']; } ?>
<?php if ($row_getResults['heading'] !=$heading) { echo "<h2 style='text-transform: uppercase; font-size: 13px; color: #333;'>".$row_getResults['heading']."</h2>"; $heading = $row_getResults['heading']; } ?>

<table width="95%" border="0" cellspacing="0" cellpadding="0" summary="this table displays the almond blossom fun run results for one mile and 8K, organized by ages of femails and males and by place, name, city, bib number, age, overall, time and pace.">
<caption>
<span style="display: none;">Almond Blossom Fun Run 2010 Results</span>
</caption>
<tr>
<th scope="col">Place</th>
<th class="name" scope="col">Name</th>
<th scope="col">City</th>
<th scope="col">Bib No.</th>
<th scope="col">Age</th>
<th scope="col">Overall</th>
<th scope="col">Time</th>
<th scope="col">Pace</th>
</tr>

<tr>
<td><?php echo $row_getResults['abr_place']; ?></td>
<td class="name"><?php echo $row_getResults['abr_name']; ?></td>
<td><?php echo $row_getResults['abr_city']; ?></td>
<td><?php echo $row_getResults['abr_bibNo']; ?></td>
<td><?php echo $row_getResults['abr_age']; ?></td>
<td><?php echo $row_getResults['abr_overall']; ?></td>
<td><?php echo $row_getResults['abr_time']; ?></td>
<td><?php echo $row_getResults['abr_pace']; ?></td>
</tr>

</table><?php } while ($row_getResults = mysql_fetch_assoc($getResults)); ?>

Remove the HTML you don’t want to be repeatedly printed out of the loop. Just leave the row and cells echoing the row results inside the loop.

I’ve tried that before, but didn’t get the results I wanted.

The attached (yukky.jpg) is what I normally get. Trying to get the ‘<th>’ out of the loop results in the other image attached (even-more-yukky.jpg); obviously not the results I’m shooting for.

yukky.jpg displays the correct results in the correct order with the correct headings (FEMALES 8 AND UNDER, MALES 8 AND UNDER, etc.), but I don’t want the repetitive <th> (Place, Name, City, etc.) to display unless it’s listing a new set of records under a new heading.

This question was answered thousand times already.
Add a condition inside of your loop.
To display a new heading only if goes “a new set of records”, whatever it meant

Not all of us are as affluent in PHP, as you are, OH MIGHTY ONE. We come here to get assistance, not feel like puny idiots. Why do you think we come here? To learn!

Also, some of us have physical issues that, sitting in front of a computer for long periods of time, tends to cause blindness and pain. So, instead of being rude, have you considered pinpointing me in the right area (such as a link) of where I can find the answer, or just help me instead?

Not all of us can sit in front of 120+ search results in a forum and search for the answer.

It looks like your already doing it for the headings
if ($row_getResults[‘heading’] !=$heading)
It’s the same for the th: if heading changes then print table header

I assumed that it was something more complex than that. I’ll see what I can come up with and come back. Thank you for the suggestion, hash.

This is what I came up with and it worked great!

<?php if ($row_getResults['heading'] !=$placeheading) { echo "<tr style='background: #bdd8da;'>
<th scope='col'>Place</th>
<th scope='col'>Name</th>
<th scope='col'>City</th>
<th scope='col'>Bib No.</th>
<th scope='col'>Age</th>
<th scope='col'>Overall</th>
<th scope='col'>Time</th>
<th scope='col'>Pace</th>
</tr>"; $placeheading = $row_getResults['heading']; } ?>

Thanks!