Code to effect every 3rd foreach

3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 12, 2010   (RSS)

Re: [jonoc73] Code to effect every 3rd foreach

By Jason - July 12, 2010

Hi Jono,

One thing you could try would be to have a counter variable that counts off each 3 records, and outputs a different div tag on the third.

Try this code:

<?php $count=1;?>

<?php foreach ($blogRecords as $record): ?>
<?php if($count!=3): ?>
<div class="box left">
<?php else: ?>
<div class="box">
<?php $count=0;?>
<?php endif ?>
<img src="<?php echo $record['list_image_url'] ?>" alt="<?php echo $record['list_image_desc'] ?>" />
<h2><?php echo $record['title'] ?></h2>
<p><?php echo $record['list_image_descs_t'] ?></p>
</div>


<?php $count++; ?>
<?php endforeach ?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Code to effect every 3rd foreach

By (Deleted User) - July 12, 2010

As usual Jason, works perfectly.

Thanks Jono