[thelist] laying out in PHP
Andrew Forsberg
andrew at thepander.co.nz
Wed Feb 27 15:03:01 CST 2002
>I've got it displaying it right, but it want to have each product spread
>across 2/3 coloumns of a table, but because I'm using a do { stuff to format
>how it is displayed } while loop while there are still records to be
>displayed, I cannot make it do it how I would like!
>Any ideas?
Hi Dave
So, you want to have a table like this:
product1 | product2 | product3
product4 | product5 | product6
product7 | product8
And you need the loop to know it needs to make empty cells to fill up
the last row?
You need a counter. In pseuod-php code:
$columnCounter = 1;
while ($row = whatever_your_db_is($result)) {
if ($columnCounter % 3 == 1) {
// output a row opening tag
// and the first column
} elseif ($columnCounter % 3 == 2) {
// output the second column
} else {
// output the third column
// and close the row
}
}
Then run a similar if/elseif/else test to clean up the last row. If
the counter %3 == 1 then you'll need to generate two blank cells, if
it's equal to 2 then generate one blank cell, etc etc...
I could be way off on what you want to achieve, though.
Cheers
Andrew
--
More information about the thelist
mailing list