How To Make Table With Alternating Color Change Colors Each Row
Posted On Sat Feb 23, 2008 By hostman In Snippets forums topics about simple codes to make programming fun Forums
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:
the output looks like this:
<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>';
?>
<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
Forums »
Snippets forums topics about simple codes to make programming fun »
How To Make Table With Alternating Color Change Colors Each Row
Snippets forums topics about simple codes to make programming fun »
How To Make Table With Alternating Color Change Colors Each Row
Title: How To Make Table With Alternating Color Change Colors Each Row
Description: How To Make Table With Alternating Color Change Colors Each Row
Tags: how ,to ,make ,table ,with ,alternating ,color ,change ,colors ,each ,row
Info: This Post Has Been Viewed 0 Times Since
Date: Sat Feb 23, 2008
Author hostman Received 0 Replies #1377
Date: Sat Feb 23, 2008
Author hostman Received 0 Replies #1377
Share
URL: 

Embed: 

To embed this topic, just copy the code from the "Embed" box. Once you've copied the code, just paste it into your website or blog to embed it
BBCODE:: 

BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums
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
copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Mon May 06, 2013 (-8 GMT)
Powered by: Webune Forums V5