Q:

Displaying results from a mySQL database ...how to add a table after X results?

I have a script that gets results from a mySQL database and then outputs them, 4 on each row, 20 total. Sort of like:
X X X X
X X X X
X X X X
X X X X

What I'm trying to do, is have the script output a piece of code (that I'll then HTMLify) after the first 4 rows. How would I do that? So that the result would be:
X X X X
something else
X X X X
X X X X
X X X X

Here is my current code:
(Note I on purpose deleted the mySQL query and that stuff, to make it easier).
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<? 
$columns = 4;
$results = 20;
for($i = 0; $i < $results; $i++)
{           
if($i % $columns == 0) { ?>
<tr height="15" valign="top">
<? } ?>
<td width="20%">OUTPUT GOES HERE</td>
<? if(($i % $columns) == ($columns - 1) || ($i + 1) == $results) { ?>
</tr>
<? } ?>
<? } ?>
</table>

A:

if ($i == 4) { /* Or 5 if you only want to show it when $results > 4 */
  echo '<tr><td colspan="4">something else</td></tr>';
}

Or am I missing something crucial?
I think your code is really hard to read and maintain, by the way. I would start by building a two-dimensional array of what I want and then output that.

