Re: Two color rows in table inside while iteration

From: Date: Fri, 30 Apr 2010 11:12:17 +0000
Subject: Re: Two color rows in table inside while iteration
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-304771@lists.php.net to get a copy of this message
On 30 April 2010 08:40, Daevid Vincent <daevid@daevid.com> 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

« previous php.general (#304771) next »