I am using PHP and I am iterating a table with a result array ... I want to add row color and alternate row color to it.... How to do so? Any suggestion...
Use modulo
$row) { ?>
', ($key % 2) ? 'odd' : 'even'); ?>
// ...
Then you can define CSS classes with the names .odd
and .even
and given them the background-color you want the rows to alternate with.
With modern browsers (read: not IE 8 or lower) you can also do it directly in CSS with the :nth-child pseudo class:
tr:nth-child(even) { background-color: #FFF; }
tr:nth-child(odd) { background-color: #EEE; }