Re: Table Making
| From: | Michael Davey | Date: | Thu, 11 Jul 2002 20:01:03 +0000 |
| Subject: | Re: Table Making | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-107220@lists.php.net to get a copy of this message | ||
How about working out the length of the column (by dividing the number of
rows by the number of cols you want), dump your results into an array and
using the col length as an offset to pick through the resulting table?
// $data is an array of results
$rows = count ($data)
$row_len = round ($rows / 3); // three cols
print "<table>";
for ($i = 0; $i < $row_len; $i++)
{
print "<tr>";
print "<td>".$data[$i]."</td>";
print "<td>".($row_len + $i < $rows)?$data[$row_len +
$i]:" "."</td>";
print "<td>".((2 * $row_len) + $i < $rows)?$data[(2 * $row_len) +
$i]:" "."</td>";
print "</tr>"
}
print "</table>";
This is off the cuff code and I think the row length's might need some extra
checking, but sth like this should work... (crosses fingers)
Mikey