View Full Version : Having trouble alternating row colors

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:


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


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

<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.


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.