RE: [PHP] Alternate row color
| From: | php3 at developersdesk dot com | Date: | Wed, 09 Aug 2000 23:38:58 +0000 |
| Subject: | RE: [PHP] Alternate row color | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-11006@lists.php.net to get a copy of this message | ||
** Reply to note from Michael Richardson <mrichardson@agex.com> Tue, 8 Aug 2000 20:12:05 -0700
>
I like this one...
$Colors = array( '#ffffff', '#000000' [, 'more-colors' ] );
$I = 0;
while( conditions ) {
print "<tr color=" . $Colors[ $I ++ % count( $Colors ) ] . ">";
}
You get to have any number of colors in the sequence. You can possibly
speed things up a little by replacing the count( $Colors ) with the
actual number of colors in the array, of you don't mind not having it
automatically adjust to changes in the array length.
>
> while (conditions) {
>
> if ($color == "#ffffff") $color = "#000000;
> else $color = "#ffffff";
>
> print "<tr color=$color></td>\n";
>
> }
>
> -----Original Message----- From: Tyler Longren
> [mailto:tyler.longren@midiowa.net] Sent: Tuesday, August 08, 2000 8:07
> PM To: PHP-General Subject: [PHP] Alternate row color
>
>
> Hello,
>
> How could I alternate table row colors by using a for or while loop?
> It can't be that hard. I just can't grasp it. I will be gettting the
> rows out of a MySQL db, and I want to alternate the colors on a page.
> Any examples?
>
Rick Widmer
Internet Marketing Specialists
www.developersdesk.com