Page is a not externally linkable
CyBerAliEn - 10:53 pm on Dec 10, 2009 (gmt 0)
Not tested, but it should work. How does it work?
Ah... I hate doing this. It sounds so easy! But it requires so much extra code for something so simple.
<?php
$color0 = "#CCCCCC";
$color1 = "#FFFFFF";
$i = 0;
foreach($data as $key => $val)
{
$useColor = ($i%2);
$thisColor = "color{$useColor}":
$thisColor = $$thisColor;
echo "<tr>";
echo "<td style=\"background-color:{$thisColor};\">".$data[$key]['NAME']."</td>";
echo "</tr>";
$i++;
}
?>
Specify the colors you want to use first (color0 is the first one used; then color1; then it repeats & alternates). You also have to setup an incrementing counter ($i). Each time the loop completes, this counter increases by 1. Inside the loop, it performs the operation ($i%2). This is mathematically: ($i)mod(2) [modulus operator]. What this does, is every loop, this operation will output: 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, etc (it continually alternates from 0 to 1, 1 to 0). It then uses some PHP variable manipulation to grab the corresponding color and inset it into the table output.