table row style alternation, need 2 records per foreach()...I think...

5 posts by 2 authors in: Forums > CMS Builder
Last Post: February 2, 2009   (RSS)

By markr - January 29, 2009

Need help with list viewer code mod.

Using data in table rows with alternating styles (e.g. background color alternates between white and gray for better visability). Need a foreach() that will give me two records then loop. Any ideas?

Re: [markr] table row style alternation, need 2 records per foreach()...I think...

By Dave - January 30, 2009

Hi markr,

Here's some code to do that:
<?php $bgColor = (@$bgColor == '#FFFFFF') ? '#666666' : '#FFFFFF'; ?>

Then you can display it like this: <?php echo $bgColor ?>

Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] table row style alternation, need 2 records per foreach()...I think...

By markr - January 31, 2009

The completed code if anyone is interested...

<h3>Contact Us</h3>
<table>
<tr>
<th>title</th>
<th>name</th>
<th>phone</th>
<th>email</th>
</tr>
<?php foreach ($contact_listRecords as $record): ?>
<?php $bgColor = (@$bgColor == '#F8F8F8') ? '#EFEFEF' : '#F8F8F8'; ?>
<tr bgcolor="<?php echo $bgColor ?>">
<td><?php echo $record['title'] ?></td>
<td><?php echo $record['name'] ?></td>
<td><?php echo $record['phone'] ?></td>
<td><a href="mailto:<?php echo $record['email'] ?>"><?php echo $record['email'] ?></a></td>
</tr>
<?php endforeach; ?>
</table>

Re: [markr] table row style alternation, need 2 records per foreach()...I think...

By Dave - February 2, 2009

Thanks! :)
Dave Edis - Senior Developer
interactivetools.com