Jump to content

Alternating Row Color


Sethm

Recommended Posts

You want to use the modulus ( % ) operator.

 

$i=0;
$x = 10;
while ($i < $x) {
    if (($i % 2) == 0) 
           echo "White <br />";
   else 
           echo "Grey <br />";
    $i++;
}

 

Is a rough example of how you would use it.

Jay,

The method you gave me worked quite smoothly.  I was a bit confused with the other one. I was trying to wrap my head around it and would have loved to understand it, but the way you presented it worked without me thinking so thank you for helping me.

 

When I get more time and don't have to slam things together I will have to learn what the modulus operator is and how it really functions - so thank you Premiso for pointing me in the right direction!

 

Seth

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.