Revision: 16502
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 6, 2009 11:54 by dizzley
Initial Code
<?php // PHP version
$i = 0;
// have_rows_to_output is a stand-in for your loop's code
while (have_rows_to_output) {
if (fmod($i, 2) == 0) { // it's an even number
output_even_style_row;
} else { // it's an odd number
output_odd_style_row;
}
$i++;
}
?>
Initial URL
http://www.nullislove.com/2007/05/09/zebra-striping/
Initial Description
This is a simple way to stripe alternate rows of output or to do anything different as I process each alternate row. Typically, I set the <tr> element's class to "myEvenRow" or "myOddRow" then output the <tr> data just after the IF statement. I found this full example at nullislove.com. The page also has a Ruby example. Full props to them.
Initial Title
Output zebra stripe rows in PHP
Initial Tags
color
Initial Language
PHP