// how many columns we want our table to have
$columns = 4;
echo "<table>\n";
for ($i = 0; $row = mysql_fetch_assoc($result); $i++) {
if (($i % $columns) == 0) {
echo " <tr>\n";
}
echo '<td><a href="view.php?id='.$row['Id'].'">';
echo '<img src="img/'.$row['Img'].'" border="0" width="142" height="100"><br /><b><strong>';
echo $row['Title'];
echo "</a><br /></strong></b>";
echo $row['Description'];
echo "<br /><small>Submitted: ";
echo $row['Time'];
echo "</small><br />";
echo '</td>';
if (($i % $columns) == ($columns - 1)) {
echo " </tr>\n";
}
}
// find out how many empty <td></td> we need to output now
// to make the html correct and well formed
$remainder = ($columns - ($i % $columns)) % $columns;
// do we have remainders?
if ($remainder > 0) {
echo str_repeat(" <td></td>\n", $remainder);
// or alternatively
// echo " <td colspan=\"$remainder\"></td>\n";
echo " </tr>\n";
}
echo "</table>\n";
}
Bookmarks