Alternating row colours
Have you ever wanted to make a table with alternating row colours?
Well I did it for a site and thought it would be great to share it. Here
PHP:
-
//connect to db and select table
-
$table = "tablename"; //table name
-
-
$list = mysql_query("SELECT * FROM `$table` ORDER BY `coulmn_name` ASC "); // the SQL of the table you will show
-
echo"
-
<h3>
-
<p align="center">$table</p>
-
</h3>
-
"; //title for the page
-
<table style="border: 1px solid black; font-family: Verdana; height: 110px;" border="0" cellspacing="1" cellpadding="2" width="500" align="center">'); //add the table
-
<tbody>
-
<tr align="center">
-
<td><strong><span style="text-decoration: underline;">Date</span></strong></td>
-
<td><strong><span style="text-decoration: underline;">description</span></strong></td>
-
</tr>
-
'); // top row with the titles
-
{
-
//chooses colous
-
if ($color == "CCFFCC")
-
{
-
$color = "FFFFFF";//change the code
-
}
-
else
-
{
-
$color = "CCFFCC"; //change the code
-
}
-
-
<tr align="center" bgcolor="#000000">
-
<td>'. $get['Date'] .'</td>
-
<td>'. $get['description'] .'</td>
-
</tr>
-
'); //add the contents
-
}
-
"); //finish the table
-
-
?>












