Wednesday, November 23, 2005

 

PHP: color every other row (aka striped rows, striping)

PHP example:
if you want every other row of a table to be colored, use the following syntax

This will color all odd rows: 1,3,5,7
<tr <?php if (++$i % 2) echo ' bgcolor="#ACEAF7" '; ?>>

This will color all event rows: 2,4,6,8
<tr <?php if ($i++ % 2) echo ' bgcolor="#ACEAF7" '; ?>>

No need to initialize or declare $i. And of course you can use any color code you want.
Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?