Re: array loops

From: Date: Sun, 03 Dec 2000 06:44:57 +0000
Subject: Re: array loops
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-28410@lists.php.net to get a copy of this message
this was discussed on another thread... anyway... the easiest way to switch table colors is while( ... ) { echo "<TD BGCOLOR=" . ? (( $count++ % 2 ) : "#000000" ? "#FFFFFF" ) . ">"; } ""Mark Lipscombe"" <mark@itgarp.com> wrote in message news:JGEGKDIOHDPHHJCDFBBDMELECKAA.mark@itgarp.com... > 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 > > > -- > 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 >

« previous php.general (#28410) next »