Jump to content

DIV or Table for MySQL output?


andreasb

Recommended Posts

Hello,

 

I'm creating a website where I want there to be 5 images per row (with several rows) with some text below each image. The image path and description is fetched from a MySQL database.

Now, which should I chose; DIV or Tables when it comes to making horizontal rows of images from MySQL?

 

I've tried using tables in the mysql_fetch_array, but the results are only 1 image per row with the description below it, so it doesn't make a horizontal line of images and descriptions.

 

Please help me out :)!

Link to comment
https://forums.phpfreaks.com/topic/194289-div-or-table-for-mysql-output/
Share on other sites

I would go with DIVs but if it's mean to be tabular data, even as images, then tables aren't so bad.  DIVs will give the most flexibility though.  Have your PHP wrap around a new DIV after five images.  Use modulous (%5) and if it returns 5, then create a new DIV section.

Since there's no natural way to do captions, you can wrap DIVs around each element to apply the text underneath the image.

 

<div class="box">
<img src="pony.jpeg">
<div class="caption">This is my pony</div>
</div>

 

Then put five of those in a single DIV for each row.  You'll have to add some styles to make it the way you want but this will give you an idea.

Yes, use the CSS to style the divs to the desired widths, heights, positions, etc. What I usually do is have wrapper divs, for example  <div class="picturesWrapper">, then inside have <div class="pictureRow"> and <div class="caption">

 

You can then easily change options from the CSS by modifying each class. I find this way of working to be very flexible when there is need for changes.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.