RE: [PHP] array loops
| From: | Mark Lipscombe | Date: | Sat, 02 Dec 2000 05:02:46 +0000 |
| Subject: | RE: [PHP] array loops | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28343@lists.php.net to get a copy of this message | ||
Easiest way I've found to switch colours on table rows is like this:
$i = 0;
while (...) {
$i++;
if (($i / 2) == floor ($i / 2)) {
echo '<tr bgcolor="#000000">' . "\n";
} else {
echo '<tr bgcolor="#FFFFFF">' . "\n";
}
...
}
Hope that helps.
Cheers,
Mark
-----Original Message-----
From: Derek Sivers [mailto:list@hitmedia.com]
Sent: Saturday, 2 December 2000 3:57 PM
To: Chris Lee
Cc: php-general@lists.php.net
Subject: Re: [PHP] array loops
>I know Im beeing picky here, but what is $i is 5?
Sorry -
I forgot to post the email I was replying to.
We were just talking about an easy way to do those
table-rows-switching-color things.
Where you really do just want to set either "$color=#FFFFFF" or
"$color=#CCCCCC"
A simple on/off. either/or.
It wasn't meant to be a big generic solution for any variable changing.
> > At 07:15 AM 12/1/00 , you wrote:
> >>while(....)
> >> {
> >> $i =+ 1;
> >>
> >> $i % 2 ? print "color 1" : "color 2";
> >> }
> >
> >
> > Another method is:
> >
> > $i = 1-$i
> >
> > So it just keeps flagging back and forth between 1 and 0.
--
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