Change row background color after each new entry
2 posts by 2 authors in: Forums > CMS Builder
Last Post: March 19, 2010 (RSS)
The site I'm building is almost ready to go online and your support has been great, thanks for that! I've got one (last?) question, which is more layout related than anything else.
I want to display a record in a table row with a white background and the next record in a table row with a grey background. Then back to white, grey, white etc....
This is the code I've got:
<tr><?php foreach ($articlesRecords as $record): ?>
<td bgcolor="#FFFFFF"><span class="style49">
<br />
<?php echo $record['content'] ?><br/>
<?php if (!$articlesRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
</span></td>
<?PHP $maxCols=1; if (@++$count % $maxCols == 0): ?></tr><tr><?PHP endif; ?> <?PHP endforeach; ?> </tr>
It works beautiful, putting each record in a new row, but how do I change the bgcolor of every row?
Thanks in advance!
I want to display a record in a table row with a white background and the next record in a table row with a grey background. Then back to white, grey, white etc....
This is the code I've got:
<tr><?php foreach ($articlesRecords as $record): ?>
<td bgcolor="#FFFFFF"><span class="style49">
<br />
<?php echo $record['content'] ?><br/>
<?php if (!$articlesRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
</span></td>
<?PHP $maxCols=1; if (@++$count % $maxCols == 0): ?></tr><tr><?PHP endif; ?> <?PHP endforeach; ?> </tr>
It works beautiful, putting each record in a new row, but how do I change the bgcolor of every row?
Thanks in advance!
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:
Then you can display it like this:
and the result was:
Hope that points you in the right direction.
Best,
Jerry Kornbluth
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
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php