Posted by ws Monkey on 12/18/99 11:48
TristaSD wrote:
> Thank for the inspiration. I used this:
>
> $num_across = 2; // Two column layout
>
> echo ("<tr>\n"); // Start the row
> while ($row = mysql_fetch_array($query)) {
> $i++; // Start the counter
> if (($i % $num_across) == 0) { // If the last column is reached
> echo "<td>$row[somename]</td></tr>\n<tr>\n"; // Close/open row
> }
> else {
> echo "<td>$row[id]</td><td>$row[artist]</td>"; // Otherwise just
> show some cells
> }
> }
> ?>
>
> </table>
>
> Thanks.
>
Looks good!
You may want to account for odd recordsets..
i.e.
3 records in the db
| td data | td data |
| td data | ........
The code would have to be set a variable that could be read outside the
while, basically seeing if the last $i iteration was odd, then stuff an
empty td line at the end.
Some more code would need to be added if you wanted the $num_rows
variable to be truly dynamic. The last iteration would have to determine
how many empty cells there were based on the $num_rows variable. (i.e.
4 records on a 3 column would result in 2 empty cells)
Will keep your html pretty and not messed up w/ browsers interpreting
strict html.
Enjoy
-- Steve
Navigation:
[Reply to this message]
|