note 92825 deleted from language.operators.logical by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 15:14:53 +0000 |
| Subject: | note 92825 deleted from language.operators.logical by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189838@lists.php.net to get a copy of this message | ||
Note Submitter: daevid at daevid dot com
----
If you ever need to alternate row colors for data output in a table, do this:
in your CSS put these two classes:
.dataRow1 { background-color: #DFDFDF; }
.dataRow2 { background-color: #FFFFFF; }
then in your PHP, loop over each row:
<?php
// ....
foreach ($foo_array as $foo) {
?><tr class="<?php echo ($dr = !$dr) ? "dataRow1" : "dataRow2";
?>"><td><?php echo $foo
?></td></tr><?php
}
?>
No need to initialize $dr as by default PHP will make it a boolean "false", then each
iteration, it will toggle true/false and substitute the CSS class