Re: that table-row-color-switching thing - again!
| From: | Sebastian Delmont | Date: | Sat, 02 Dec 2000 08:09:19 +0000 |
| Subject: | Re: that table-row-color-switching thing - again! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28351@lists.php.net to get a copy of this message | ||
I think this is actually nicer... a one-liner :-)
while(...) {
$color = ($count++ % 2) ? "#eeeeee" : "#ffffff";
}
since you might want to use the count for something else (or you might
already have it)...
And the mod operator (that's the %) works for more than two colors too...
$colors = array( "blue", "red", "green" );
while(...) {
$color = $colors[ $count++ % count( $colors ) ];
}
Regards,
Sebastian
"Derek Sivers" <list@hitmedia.com> wrote in message
news:4.2.0.58.20001201232700.009e1920@mail.cdbaby.com...
> just to beat a dead horse...
>
> here's the most efficient way I've found to change HTML table row colors
as
> you loop through an array of info:
>
>
> $row = 1-$row;
> $color = ($row==0)?"#eeeeee":"#ffffff";
>
>
> that's it. just those two lines. (use $color for <td bgcolor=$color>)
> you don't need to define $row or $color beforehand.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>