RE: [PHP] Alternate Colors in Rows
| From: | Daevid Vincent | Date: | Thu, 04 Oct 2007 19:28:23 +0000 |
| Subject: | RE: [PHP] Alternate Colors in Rows | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-262767@lists.php.net to get a copy of this message | ||
This was a joke right? You don't seriously do this in r.l. just to alternate
row colors I hope?
> -----Original Message-----
> From: Robert Cummings [mailto:robert@interjinn.com]
> Sent: Wednesday, October 03, 2007 6:36 PM
> To: Jim Lucas
> Cc: Steve Marquez; PHP eMail List
> Subject: Re: [PHP] Alternate Colors in Rows
>
> 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!
> ...........................................................
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>