RE: [PHP] change color

From: Date: Tue, 27 May 2003 03:15:28 +0000
Subject: RE: [PHP] change color
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-149043@lists.php.net to get a copy of this message
I think $bgcolor = (++$i & 1) ? 'red' : 'green'; within your loop has been proven to be the fastest overall. Just put $bgcolor wherever you need it within your loop... while($something) { $bgcolor = (++$i & 1) ? 'red' : 'green'; echo "<tr bgcolor=\"$bgcolor\"><td>Cell</td></tr>"; } Be sure to initialize $i to something ($i = 0;) prior to this so you don't get a warning on the first loop. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ > -----Original Message----- > From: Tom Ray [Lists] [mailto:lists@blazestudios.com] > Sent: Monday, May 26, 2003 11:01 PM > To: php-general@lists.php.net > Subject: Re: [PHP] change color > > This was a question I've been kicking around myself. But Evan's answer > is a bit confusing to me, can someone clear it up? Evan, can you explain > it a bit better? Maybe show how it is supposed to look in the overall > code? > > Thanks! > > Evan Nemerson wrote: > > >echo (($i % 2) == 0) ? "Color 1": "Color 2"; > > > > > >On Monday 26 May 2003 07:29 pm, Aris Santillan wrote: > > > > > >>hi > >> > >>how can i alternate row color for this routine? > >> > >><? > >> > >>$query = mysql_query("SELECT * from data"); > >>$num = mysql_num_rows($query); > >>for($i=0; $i<=$num; $i++) > >> { > >> $row = mysql_fetch_array($query); > >> echo $row[0]; > >> } > >> > >> > >>?> > >> > >> > > > > > >

« previous php.general (#149043) next »