- Impact
- 20
everytime ive looked about at alternate row colors seen some long code which just isnt nesacary imo
heres the easyway, 3 variables, 1 if statement which can be nested in an iffstament
but heres the code
heres the code in an example
heres a demo
http://www.crooty.co.uk/scripts/alternaterows.php
it basically says if bgcolor equals bgcolor1 set bgcolor as bgcolor 2 and then it swaps it around and does it every time
heres the easyway, 3 variables, 1 if statement which can be nested in an iffstament
but heres the code
PHP:
// the variables
$bgcolor="#c0c0c0";
$bgcolor1="#EFEFEF";
$bgcolor2="#c0c0c0"; // for one color leave this feild empty
// the if statment
if($bgcolor==$bgcolor1)
{
$bgcolor=$bgcolor2;
}
else
{
$bgcolor=$bgcolor1;
}
heres the code in an example
PHP:
echo "<table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\">";
$bgcolor="#c0c0c0";
$bgcolor1="#EFEFEF";
$bgcolor2="";
$i=0;
while($i < 30)
{
if($bgcolor==$bgcolor1)
{
$bgcolor=$bgcolor2;
}
else
{
$bgcolor=$bgcolor1;
}
echo "<tr bgcolor=$bgcolor><td>background color is $bgcolor</td></tr>";
$i++;
}
echo "</table>";
heres a demo
http://www.crooty.co.uk/scripts/alternaterows.php
it basically says if bgcolor equals bgcolor1 set bgcolor as bgcolor 2 and then it swaps it around and does it every time
Last edited: