Friday, April 01, 2005

Alternate Coloured Rows in PHP

How to create alternate coloured rows when displaying data from a database in PHP:

$colarr=array("#cccccc","#ffffff"); //create an array containting color values

while($row=mysql_fetch_array($result))
{
echo "\n";
echo "\t\n$row[1]";
//shuffling the color array
array_unshift($colarr,$colarr[1]);
array_pop($colarr);
}

No comments: