Want to create dynamic div from database query

#1
[eluser]RMinor[/eluser]
I am trying to display events for a particular profile from a database in rows of 3. I do not want to use a table as the template I am using has nice styling built in. Here is my code so far. Currently it is not writing the first div and it is stacking them on top of each other on the left side. I need these in rows of three even if there aren't three coming from the database. Any help is appreciated.

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

Here is how I want it to look. How would I edit my code to get this?
Code:
<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>


#2
[eluser]ppwalks[/eluser]
Array chunk


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.