im cutting and pasting some code, you will need to adapt it.
PHP Code:
// how many columns we want our table to have
$columns = 3;
echo "<table>\n";
for ($i = 0; $row = mysql_fetch_assoc($result); $i++) {
if (($i % $columns) == 0) {
echo " <tr>\n";
}
echo " <td>" . $row['fieldname'] . "</td>\n";
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";
you could also do similar with array_chunk() and array_pad()
Bookmarks