Re: Two color rows in table inside while iteration

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

 



On 30 April 2010 08:40, Daevid Vincent <daevid@xxxxxxxxxx> wrote:
>> -----Original Message-----
>> while(foo){
>> $tr = (0 == $trColor % 2)? "#E8E8E8" : "#FFFFFF";
>> echo "<tr style=\"background-color:".$tr."\">";
>> ...
>
> Don't do this modulus (%) math!!!! Just toggle a boolean!!
>
> <tr class="<?= ($r = !$r) ? "dataRow1" : "dataRow2"; ?>">
>

The modulus is a good option when there are more than 2 states.

Say a 5 row fade ...

$a=0;
while ($row=mysql_fetch_...){
echo "<tr class=‌‌‌‌‌‌\"alternate-row-".(1 + (++$a%5))."\"><..."
}

giving alternate-row-1, alternate-row-2, alternate-row-3,
alternate-row-4 and alternate-row-5


-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

-- 
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