Wallpapers Forums Login

How To Make Table With Alternating Color Change Colors Each Row

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:

Related Content

Information

Share

wallpaperama | Wallpapers | Forums | Terms Of Service

copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Mon May 06, 2013 (-8 GMT)
Powered by: Webune Forums V5