Griffith, the modulus (%) operator is what you want. It divides one number by another and returns the remainder. You can read more about it in the php manual. Anyway, the way you would do it is something like this:
//HTML starts here
<table>
<tr>
//PHP starts here
<?php
$count = 1;
while ($entry = $d->read()) {
if (($entry != "..") && ($entry != ".")) {
echo "<td>$where.$entry</td>\n";
if (($count % 4) == 0) {
echo "</tr><tr>\n";
}
}
$count++;
}
//End of PHP
?>
//End of HTML
</tr>
</table>