...

View Full Version : Having trouble alternating row colors



bucket
08-29-2011, 08:36 PM
I cant figure out why it isnt working.

I put I think all the correct things.

Here is how it looks:


<?php

//alternating row colors
$color1 = "#CCFFCC";
$color2 = "#BFD8BC";
$i = 1;

while($rows=mysql_fetch_array($result)){


if($i%2 == 1) {
$color = $color1; }
else { $color = $color2; }

?>
<tr>
<td align="center" bgcolor="<?php echo $color; ?>"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>

But for some reason its showing the same color for all the rows.

Preview: http://brian.ubietymedia.com/project/

You can see that the first row is the same color instead of alternating green and red.

If the whole script is needed, il be glad to post it.

:)

Fou-Lu
08-29-2011, 08:39 PM
You are not incrementing $i. Change that to if ($i++ % 2 == 1), and you should see the alternating rows.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum