my simple way.. while(....) { $i += 1; $alt = ($i % 2) ? 'alt1' : 'alt2'; } then just use $alt in your <td> class.. ----- Original Message ----- From: "Graham Cossey" <graham.cossey@xxxxxxxxx> To: "Brad Ciszewski" <bradcis@xxxxxxxxxxx> Cc: <php-general@xxxxxxxxxxxxx> Sent: Saturday, December 11, 2004 8:33 AM Subject: Re: alternating table entry colors > On Fri, 10 Dec 2004 18:19:35 -0600, Brad Ciszewski <bradcis@xxxxxxxxxxx> 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 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php