- Forums
- Snippets
- How To Make Table With Alternating Color Change Colors Each Row
This Page Contains information about How To Make Table With Alternating Color Change Colors Each Row By wallpaperama in category Snippets with 0 Replies. [1377], Last Updated: Tue Feb 07, 2023
wallpaperama
Sat Feb 23, 2008
0 Comments
1685 Visits
sometimes when you retrieve data from a database its a good idea to have each row in different colors to distinguish each row from another. there is a good and simple snippet you can use as an example. just copy and past this code into your text editor and save it as webune.php and then upload to your website and open it with your browser you will see the alternating colors:
<h1><a href="http://www.webune.com">WWW.WEBUBE.COM</a></h1>
<h1>Alternating Colors Table</h1>
<?
$myrow = array();
//[0] => 'site_url', [1] => 'site_url', [2] => 'http://localhost/myscripts/mypages/', [3] => 'http://localhost/myscripts/mypages/', [4] => 'WWW Address', [5] => 'WWW Address'
$myrow[0] = 'ZERO';
$myrow[1] = 'ONE';
$myrow[2] = 'TWO';
$myrow[3] = 'THREE';
$myrow[4] = 'FOUR';
$myrow[5] = 'FIVE';
$myrow[6] = 'SIX';
echo '<table border="1" cellpadding="5" cellspacing="1">';
for($i =0; $i < count($myrow); $i++) {
if($bgcolor == "E8FAFF") {$bgcolor = "FFFFFF";} else {$bgcolor = "E8FAFF";}
echo '<tr bgcolor="'.$bgcolor.'"><td>'.$i.'</td><td>'.$myrow[$i].'</td></tr>';
}
echo '</table>';
?>
the output looks like this: