Click to See Complete Forum and Search --> : Another thread: alternating row colour


Daot Lagorille
08-14-2003, 08:46 AM
Yet more crap from me, this time, I will keep it short.

Can someone point me in the right direction to find a bit of the ol' php script that will help me to make alternating bgcolor values in a repeating <tr> (I am using the venerable "do while" manouver to make the repeating reagion)?

Faithfully yours, but not in a stalker-kind-of-way,

DlaG

pyro
08-15-2003, 07:50 AM
You can use the modulous operator to do this:

<table border="1">
<?PHP
$x = 0;
do {
if ($x % 2 == 0) {
echo ("<tr style=\"background-color: #eeeeee;\"><td>$x</td></tr>\n");
}
else {
echo ("<tr style=\"background-color: #dddddd;\"><td>$x</td></tr>\n");
}
$x++;
}
while ($x < 10);
?>
</table>

The if ($x % 2 == 0) will check for all even rows (when $x is an even number).