RyanMinor Posted December 8, 2012 Share Posted December 8, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/271738-php-dynamic-grid-output-similar-to-table/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.