I'm working on the website for my freelance design services, and I'm at the point of developing a portfolio page. The client images and details are stored in a SQLite database. I would like to recursively split the items returned from a query into rows of 5 using a table. The code I have for the moment is:
Code:
$result = $db->query("SELECT * FROM clients ORDER BY id DESC");
$clients = $result->fetchAll();
echo "<table width='100%' cellspacing='3'>\n";
$column = 1;
foreach ($clients as $client) {
if ($column == 1) {
echo "\t<tr>\n";
}
$column++;
echo "\t\t<td><a href='client.php?id=" . $client['id'] . "' class='lbOn'><img src='clients/" . $client['imgname'] . ".jpg'></a></td>\n";
if ($column == 5) {
echo "\t</tr>\n";
$column = 1;
}
}
echo "</table>";
This works good, except for one thing... if the last row contains less than 5 images, then no </tr> is added, making the page invalid. Normally, this wouldn't bother me, but since this is my portfolio, I would like to make it validate. I figured I could determine at the beginning if the number of rows returned will create an even table (5 items on every row), then if it won't (less than 5 on the last row), it adds the </tr> to end automatically. But, I have no idea how to figure out if the number of rows returned will create exactly 5 items on every row.
Any ideas?