How To Make Table With Alternating Color Change Colors Each Row
how to make table with alternating color change colors each row
how, to, make, table, with, alternating, color, change, colors, each, row
How To Make Table With Alternating Color Change Colors Each Row
Post Description: how to make table with alternating color change colors each row
POST# 1061
Posted On: Fri Feb 29, 2008 12:01 pm
web hosting
Topic: 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:
Share:
BBCODE:
HTML Code:


No Repies
(0) Comments for How To Make Table With Alternating Color Change Colors Each Row

What do you think?

* name:  

* email:  

* Please enter comments:


Receive Replies on my Comments
(An email will be sent to you when someone replies to your comments)

Add image to comments
yes no             upload