[SOLVED] Tables : Alternating Colours

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

[SOLVED] Tables : Alternating Colours

Post 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";
}
Last edited by facets on Tue May 31, 2005 7:07 am, edited 1 time in total.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post 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";
}
Post Reply