Need better idea for color changing table
Posted: Wed Apr 14, 2004 6:21 pm
I am pretty new to php, and I am creating a table that the background color changes on ever other entry. I have it working, but I know there has got to be a better way. Below is my code. Please feel free to reply with any better ideas. It would be much appreciated. thanks "WARNING: the below code may make you laugh!"
Code: Select all
<?php
//create list block of results
$record_list ="<table border="0" cellpadding="0" cellspacing="0"><tr><td width="200"><h3>NAME</h3>";
$record_list .="</td><td><h3>USER NAME</h3></td></tr>";
while ($row = mysql_fetch_array($result)) {
$count += 1;
if (($count == "1") || ($count == "3") || ($count == "5") || ($count == "7") ||
($count == "9") || ($count == "11") || ($count == "13") || ($count == "15") ||
($count == "17") || ($count == "19") || ($count == "21")) {
$color = "CCCCFF";
} else {
$color = "CCCCCC";
}
$user_id = $row['user_id'];
$user_name = $row['user_name'];
$record_list .= "<tr><td bgcolor="$color">";
$record_list .= "<a href="index.php?main=show_record&user_id=$user_id" style="text-decoration:none"><strong>$user_name</strong></a>";
$record_list .= "</td><td width="200" bgcolor="$color"><strong>$user_id</strong></td></tr>";
}
$record_list .="</table>";
?>