Jump to content

Php Dynamic Grid Output Similar To Table


RyanMinor

Recommended Posts

Hello, I am trying to output a grid of 3 columns (even if there is only 2 rows returned from the database) similar to a data table, but with divs instead. The data is coming from the database. Below is my current code (which is not working):

 

<?php $end_row = 0;
$columns = 3;
$loop = 0;
foreach ($events as $event) {
if ($end_row == 0 && $loop++ != 0) { ?>
<div class="left13 section_home">
<?php } ?>
<h2><?php echo $event['event_title']; ?></h2>
<a href="#"><img src="<?php echo ($event['photo_thumbnail'] != '') ? base_url() . 'media/photos/thumbnail/' . $event['photo_thumbnail'] : base_url() . 'images/no_photo_thumbnail.png'; ?>" alt="" title="" /></a>
<p><?php echo ($event['event_description'] != '') ? substr($event['event_description'], 0, strpos($event['event_description'], ' ', 200)) : 'No description yet...'; ?></p>
<a href="#" class="section_more"><span class="swirl_left"><span class="swirl_right">View This Event</span></span></a>
<?php $end_row++;
if($end_row >= $columns) { ?>
</div>
<?php $end_row = 0;
}
}
if ($end_row != 0) {
while ($end_row < $columns) { ?>
<div class="left13 section_home"> </div>
<?php $end_row++;
} ?>
<?php } ?>

 

Here is how it should look. How can I adjust my current code to get this?

<div class="left13 section_home">
<h2>Wedding <span>Location</span></h2>
<a href="#"><img src="images/image_13.jpg" alt="" title="" /></a>
<p>Ut enim ad minima veniam, quis nostru <strong>exercitationem</strong> ullam corporis laboriosam, nisi ut aliquid ex ea commodi <strong><a href="#">consequatur</a></strong>
</p>
<a href="#" class="section_more"><span class="swirl_left"><span class="swirl_right">read more</span></span></a>
</div>

<div class="left13 section_home">
<h2>Honeymoon <span>Destination</span></h2>
<a href="#"><img src="images/image_13_2.jpg" alt="" title="" /></a>
<p>Ut enim ad minima veniam, quis nostru <strong>exercitationem</strong> ullam corporis laboriosam, nisi ut aliquid ex ea commodi <strong><a href="#">consequatur</a></strong>
</p>
<a href="#" class="section_more"><span class="swirl_left"><span class="swirl_right">read more</span></span></a>
</div>

<div class="left13 section_home">
<h2>Girft <span>Registry</span></h2>
<a href="#"><img src="images/image_13_3.jpg" alt="" title="" /></a>
<p>Ut enim ad minima veniam, quis nostru <strong>exercitationem</strong> ullam corporis laboriosam, nisi ut aliquid ex ea commodi <strong><a href="#">consequatur</a></strong>
</p>
<a href="#" class="section_more"><span class="swirl_left"><span class="swirl_right">read more</span></span></a>
</div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.