RE: Alternate Colors in Rows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx] 
> Sent: Wednesday, October 03, 2007 6:36 PM
> To: Jim Lucas
> Cc: Steve Marquez; PHP eMail List
> Subject: Re:  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
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux