|
Posted by Rik on 02/09/07 02:42
eholz1 <ewholz@gmail.com> wrote:
> Hello PHP users,
>
> I have a question, I would like to create a table on the fly, with
> PHP. I have typically done this just
> using the <?php echo ('<table><tr><td>some nice data</td><td>some
> nicer data</td></tr></table'); ?>
>
> sometimes I concatenate the tags: echo '<td>' . 'my data' . '</td>',
> etc.
>
> It is my desire to build a table with attributes (happily, mostly the
> same) like border, padding, cellpadding, cellspacing, etc.
All attributes that are much better served with css, so just give the =
table a class or id and adjust your css accordingly.
> I will be creating the td's, and tr's based on how many images I pull
> out of a MYSQL database.
> so if I have 20 thumbnail images, I will end up with a table 4 thumbs
> across, and 5 rows.
What should be the logic? Saying it's dependant on the number with one =
example does not explain your intentions. It could be divided =
1x20,2x10,4x5,5x4,10x2,20x1, and a lot of other possibilities with empty=
=
cells.
> I am thinking about using a loop from the query in the db, which gives=
> me the image name, location, width,height, etc
> and using the image data from the db, and adding the various table
> tags to the php code.
>
> any info on how to do this like a "real" programmer will help,
1. determine the dimensions based on the number of images
2. have a counter in your while loop
3. start a new row every N images, possibly using if($counter % N =3D=3D=
0)
4. clean up the table for good measure by echoing either empty cells =
untill the end of the row or one with a specific colspan.
Then again, from an HTML standpoint this seems not to be a table. I'd sa=
y: =
just float the images to the left, possibly in their own div, and live =
get's just a little easier, and your html sementically correct. When =
they're a genuine list use <ul> and <li> accordingly, with inline or =
floated <li>'s
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|