Forum Moderators: coopster
Example in a while() loop:
$counter = 0;
while ($i = mysql_fetch_array($result)){
$counter++; // increases by one on each iteration of loop
if (is_float($counter/2)) $class = "gray";
else $class = "white";
print "<td class=\"".$class."\">stuff</td>"; // either gray or white
}
Welcome to Webmaster World, megajam02!
Birdman
$counter = 0;
while(etc)
{
/*will be true for odd numbers
change to $counter & 0 if you want it to be true
for even numbers */
if($counter & 1)
{
etc...
}
$counter++;
}
Remember these are binary. Numbers will go
0000
0001
0010
0011
etc., and the LSD will alternate 0/1. This is the fastest method of testing for an even or odd number (using a bitwise and). Using MOD is a good way to do it, but it's slow.
Here is my original code:
<?php do {?>
<tr>
<td height="16"><span class="style20"><?php echo $row_Recordset1['username'];?></span></td>
<td><span class="style20"><?php echo $row_Recordset1['user_firstname'];?></span></td>
<td><span class="style20"><?php echo $row_Recordset1['user_lastname'];?></span></td>
<td><span class="style20"><?php echo $row_Recordset1['user_website'];?></span></td>
<td><span class="style20"><?php echo $row_Recordset1['user_email'];?></span></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));?>
Would anyone be willing to edit it for me so I can see exactly how to use your suggestion.
<?php
$counter = 0;
do {
$color = ($counter & 1)? "#fff" : "#666";
$counter++
?>
<tr style="background: <?php print $color;?>;">
...
...
...
...
</tr>
<?php
} while (
$row_Recordset1 = mysql_fetch_assoc($Recordset1)
)
;
Not sure if that last semicolon is needed.