Me n My Programming

If Only I Have TIme

Alternate table color in php

This is how I made my alternate table colored 🙂

<?

echo “<table border = ‘1’ cellpadding=’5′>”;
echo “<tr bgcolor=’#9999CC’>”;
echo “<td>No.</td>”;
echo “<td>Grant Title</td>”;
echo “<td>Grant Leader</td>”;
echo “<td>Grant Type</td>”;
echo “<td>Status</td>”;
echo “</tr>”;
while ($row = mysql_fetch_array($sql,MYSQL_ASSOC))
{
$color = ( $i % 2 ? ‘#FCFCFC’ : ‘#9999CC’ );

echo “<tr bgcolor='”.$color.”‘>”;
echo “<td>&nbsp;”.$i.”</td>”;
echo “<td>”.$row[‘title’].”</td>”;
echo “<td>”.$row[‘leader’].”</td>”;
echo “<td>”.$row[‘grant’].”</td>”;
echo “<td>”.$row[‘status’].”</td>”;
echo “</tr>”;
$i++;
}
echo “</table>”;

?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on August 7, 2008 by in Php and tagged .
%d bloggers like this: