PHP Alternate table colors

I’m having some issues with formatting. I figured out how to add a table within a loop to output the data. But I need some help adding alternate row colors to this table. Could html5 be used?

This is what I have so far

echo “

”;
while($row = mysql_fetch_array($result))
{
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo "</tr>";

}

echo “

” .$row[‘firstname’]. “ ”. $row[‘lastname’]. “” .$row[‘address’]. “ ”. $row[‘city’]. “” .$row[‘state’]. “” .$row[‘zipcode’]. “ ”. $row[‘phone1’]. “” .$row[‘phonenum’]. “ ”. $row[‘email’]. “” .$row[‘day1’]. “ ”. $row[‘day2’]. “” .$row[‘package’]. “
”;

Hi there,

Try adding what’s in bold:


echo “

”;
$i = 0;
while($row = mysql_fetch_array($result))
{
if($i%2)
$color = “#FFFFFF”;
else
$color = “#CCCCFF”;

echo “”;
echo “<td bgcolor=".$color.">” .$row[‘firstname’]. “<td bgcolor=".$color.">”. $row[‘lastname’]. “”;
echo “<td bgcolor=".$color.">” .$row[‘address’]. “<td bgcolor=".$color.">”. $row[‘city’]. “”;
echo “<td bgcolor=".$color.">” .$row[‘state’]. “”;
echo “<td bgcolor=".$color.">” .$row[‘zipcode’]. “<td bgcolor=".$color.">”. $row[‘phone1’]. “”;
echo “<td bgcolor=".$color.">” .$row[‘phonenum’]. “<td bgcolor=".$color.">”. $row[‘email’]. “”;
echo “<td bgcolor=".$color.">” .$row[‘day1’]. “<td bgcolor=".$color.">”. $row[‘day2’]. “”;
echo “<td bgcolor=".$color.">” .$row[‘package’]. “”;
echo “”;
$i++;
}

echo “

”;

Hope this helps.

Sponsor our Newsletter | Privacy Policy | Terms of Service