Page 1 of 1

[SOLVED] Tables : Alternating Colours

Posted: Tue May 31, 2005 6:14 am
by facets
Hi,

With the following code, any ideas on how I would alternate <td> Colours.
Row1=Grey;
Row2=Silver;

Cheers, Wil.

Code: Select all

$viewFaceStockSpecDesc=array('Description','Basis Weight','Caliper','Wet Tensile Strength CD','Dry Tensile Strength CD','Wet Tensile Strength MD','Dry Tensile Strength CD','Opacity','Gloss','Brightness','Moisture Content','Relative Humidity','Absorption','Smoothness','Tear Strength CD','Tear Strength MD','Burst Strength','PH');
$name = array("$description","$basisWeight","$caliper","$wetTensileStrenghtCD","$wetTensileStrenghtMD","$dryTensileStrengthCD","$dryTensileStrengthMD","$opacity","$gloss","$brightness","$moistureContent","$relativeHumitity","$absorbtion","$smoothness","$tearStrengthCD","$tearStrengthMD","$burstStrength","$pH");
for($x = 0; $x<count($viewFaceStockSpecDesc); $x++)
{
  echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$viewFaceStockSpecDesc[$x]."</td>\n";
  echo "<td width=\"200px\" colspan=\"2\">".$name[$x]."</td></tr>\n";
}

Posted: Tue May 31, 2005 6:22 am
by phpScott
you can look at viewtopic.php?p=176863&highlight=#176863 to get an idea of how to do this.

look at the first post carefully :D

Posted: Tue May 31, 2005 6:34 am
by facets
Thanks!
It certainly helps if your CSS isn't overriding things :)

Code: Select all

for($x = 0; $x<count($viewFaceStockSpecDesc); $x++)
{
    if($x % 2) 
    {
	    echo "<TR bgcolor=\"#ffff99\">\n";
    } 
    else 
    {
	    echo "<TR bgcolor=\"#ffffcc\">\n";
    }
	
  echo "<td width=\"200px\" colspan=\"2\" valign=\"top\">".$viewFaceStockSpecDesc[$x]."</td>\n";
  echo "<td width=\"200px\" colspan=\"2\">".$name[$x]."</td></tr>\n";
}