Re: Alternate Colors in Rows

From: Date: Thu, 04 Oct 2007 01:35:47 +0000
Subject: Re: Alternate Colors in Rows
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-262721@lists.php.net to get a copy of this message
In the following example I show a simple OOP example (because I felt like it) and illustrate why using CSS classes is the most powerful way to do row style cycling. Hopefully you're using a decent browser (almost anything other than IE -- I recommend Opera :) but if not then IE7 will suffice to illustrate hover properly (finally). <?php class SillyCycle { var $period = 2; var $index = -1; function SillyCycle( $period=2 ) { $this->period = (int)$period; $this->reset(); } function reset() { $this->index = -1; } function getIndex() { if( $this->period ) { return ($this->index = (++$this->index % $this->period)) + 1; } return 1; } } $cycle = new SillyCycle(); ?> <html> <head> <style> table.example { border: solid 1px #444444; } table.example th, table.example td { padding: 2px 4px 2px 4px; text-align: center; } table.example th { background: #d8d8d8; } table.example tr.cycle_1 td { background: #e8e8e8; } table.example tr.cycle_2 td { background: #e0e0e0; } table.example tr.cycle_1:hover td { background: #bbbbe8; } table.example tr.cycle_2:hover td { background: #bbbbe0; } </style> </head> <body> <table class="example" cellspacing="1"> <tr> <th>Col 1</th> <th>Col 2</th> <th>Col 3</th> </tr> <?php for( $i = 1; $i <= 50; $i++ ) { ?> <tr class="cycle_<?php echo $cycle->getIndex() ?>"> <td><?php echo $i ?></td> <td>:)</td> <td>;)</td> </tr> <?php } ?> </table> </body> </html> -- ........................................................... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ...........................................................

« previous php.general (#262721) next »