Change row background color after each new entry

2 posts by 2 authors in: Forums > CMS Builder
Last Post: March 19, 2010   (RSS)

Re: [Hansaardappel] Change row background color after each new entry

By gkornbluth - March 19, 2010 - edited: March 23, 2010

Hi Hansaardappel,

Here's an recipe from my CMSB Cookbook http://www.thecmsbcookbook.com
that describes how to accomplish that.

ALTERNATING THE BACKGROUND COLOR OF TABLE ROWS
Markr wanted to know how to automatically alternate between 2 background colors in a table.

Dave Edis, as always, had an effective approach, he said:

Here's some code to do that:

<?php $bgColor = (@$bgColor == '#F8F8F8') ? '#EFEFEF' : '#F8F8F8'; ?>

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

and the result was:

<table>
<tr>
<th>title</th>
<th>name</th>
<th>phone</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>
</tr>
<?php endforeach; ?>
</table>


Hope that points you in the right direction.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php