RE: [PHP] Two color rows in table inside while iteration -- just say no to mod
| From: | Daevid Vincent | Date: | Fri, 30 Apr 2010 20:20:17 +0000 |
| Subject: | RE: [PHP] Two color rows in table inside while iteration -- just say no to mod | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-304792@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Ashley Sheridan [mailto:ash@ashleysheridan.co.uk]
>
> Modulus is the most elegant solution I reckon. Imagine if you only
> needed to highlight every 3rd row, or 4th? Easy to change the modulus
> for it, not so easy to re-work a binary switch.
>
> -----Original Message-----
> From: Richard Quadling [mailto:rquadling@googlemail.com]
>
> 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
Okay, how many tables do you EVER see with more than TWO colors? Come on
now.
Show me some URL's to REAL sites (not some contrived examples) that use
multiple row colors or fades in a rotating fashion. Not talking about a
highlight roll-over, nor am I talking about highlighting rows of certain
criteria in different colors, as both of those are not the problem for this
solution. I'm talking about a straight up table that cycles each row more
than 2 colors.
99% of your tables are 2 colors, and flipping a bit (i.e. Boolean) is WAY
faster to compute than modulus and also easier to understand.
http://www.youtube.com/watch?v=pXhKzY0BKwY
;-) (I say that out of love!)
d