Forum Moderators: phranque
1. If ordination of the data other than the autoincrement id field is required, create a sequencing field in which you determine the data's sequence.
(Ascending is default)
"select data from table order by sequence_field"
2. Create a switch that determines start and end of table data rows.
$cols = 0; ## this is your switch.
$colcount = 2; ## This is the number of columns
print "<table">;
while (($data)=$sth->fetchrow_array) {
if ($cols == 0) { print "<tr>"; }
print "<td>$data</td>";
$cols++;
if ($cols > $colcount) {
print "</tr>";
$cols = 0; ## reset to 0. Next loop entry adds new <tr>
}
}
3. Create an error-free table close: If you've finished with an odd number (without closing </tr>) loop through to create empty cells. Although your example uses only two, this would fill out to $colcount columns.
if (($cols >0) && ($cols < $colcount)) {
for $i ($cols..$colcount) { print "<td> </td>"; }
print "</tr>";
}
print "</table>";
Of course there are other ways but this is one.