foreach - display diff bgcolor
Posted by: ucurl
Posted on: 2002-10-15 18:17:00
Is there a way to change the background color on each row displayed using a foreach statement. I've tried to add an if statement at the end of this to change the color but it does not work. Am I using the foreach incorrectly?
my example
echo "n<Table border=0 valign=top align=center><font face=Arial size=1>n";
echo "n<b><tr>";
echo "n<th>Code</th>" .
"n<th>First Name</th>" .
"n<th>Last Name</th>" .
"n<th>Home Phone</th>" .
"n<th>Bus. Phone</th>" .
"n<th>Name</th>" .
"n</tr></b>";
$currbackcolor = "silver";
While ($row = @ mysql_fetch_row($result))
{
echo "n<tr>";
foreach($row as $data)
echo "nt<td bgcolor=$currbackcolour><b><font color="white"> $data </b></td>";
echo "n</tr>";
// Add If statement to change back colour
If ($currbackcolor = "silver")
$newbackcolor = "blue";
else
$newbackcolor "silver";
}
Echo "n</Table>n";