Re: alternating table entry colors

From: Date: Sat, 11 Dec 2004 13:33:19 +0000
Subject: Re: alternating table entry colors
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-204052@lists.php.net to get a copy of this message
On Fri, 10 Dec 2004 18:19:35 -0600, Brad Ciszewski <bradcis@charter.net> wrote: > i need some assistance making my table (rows) change color for every other > data. here is what i have so far, but i get a "unexpected T_STRING error". > this error's line is: if($thisRow mode 2 == 0){ > > +=+=+ SCRIPT BELOW +=+=+ > > $thisRow = 0; > > $query = mysql_query("SELECT * FROM security_images ORDER BY ID DESC"); > while($gt=mysql_fetch_array($query)){ > if($thisRow mode 2 == 0){ > $backgroundColor = "#CCCCCC"; > }else{ > $backgroundColor = "#FFFFFF"; > } > > extract($gt); > echo ?> > <tr bgcolor="<?PHP echo($backgroundColor); ?>"> > <td><?PHP echo($ID); ?></td> > <td><?PHP echo($ipAddr); ?></td> > <td><?PHP echo($area); ?></td> > <td><?PHP echo($insertdate); ?></td> > <td><?PHP echo($referenceid); ?></td> > <td><?PHP echo($hiddentext); ?></td> > </tr> > <?PHP > $thisRow++ > } ?> > > +=+=+ SCRIPT ABOVE +=+=+ > > thanx in advance! > How about : <?php $rowNum = 0; $bg = array("#CCCCCC", "#FFFFFF"); run query while ( query_results) { ?> <tr bgcolor="<?=$bg[$rowNum]?>"> <td>... <?php $rowNum = ($rowNum==0)?1:0; } ?> I normally use a CSS stylesheet with entries called tableRow0 and tableRow1 and then have the <TR> as: <TR CLASS="tableRow<?=$rowNum?>"> HTH Graham

« previous php.general (#204052) next »