Alternating Table Row Colors
Posted by Santhosh Kuma on May 22nd, 2008This tutorial will provide you with a basic concept for creating alternating row colors. Using while loops and generating a list from the mysql table.
Firstly, Save the sql structure below as data.sql and upload the sources to your mysql database
# # Table structure for table data_list # CREATE TABLE `data_list` ( `id` int(11) NOT NULL auto_increment, `name` varchar(50) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM; # # Dumping data for table data_list # INSERT INTO `data_list` VALUES (1,'Ford'); INSERT INTO `data_list` VALUES (2,'Toyota'); INSERT INTO `data_list` VALUES (3,'Mitsubishi'); INSERT INTO `data_list` VALUES (4,'Honda'); INSERT INTO `data_list` VALUES (5,'Chevrolet'); INSERT INTO `data_list` VALUES (6,'Mercidez Benz'); INSERT INTO `data_list` VALUES (7,'Isuzu'); INSERT INTO `data_list` VALUES (8,'Jeep'); INSERT INTO `data_list` VALUES (9,'Suzuki'); |
Secondly, Once you have done creating and uploading your database structure. You can start working on table.php.
1 2 3 4 5 6 7 8 9 | <?php $dbhost = 'localhost'; // Change to your host. $dbuser = 'USERNAME'; // Change to your user. $dbpass = 'PASSWORD'; // Change to your password. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); // $dbname relates to the database name you gave when setting up the mysql settings. $dbname = 'DATABASENAME'; mysql_select_db($dbname); ?> |
10 11 12 13 | <table border="1"><tr> <td bgcolor="#FF9900"><strong>No.</strong></td> <td bgcolor="#FF9900"><strong>Company</strong></td> </tr> |
This section above is the start of the table with its headers
The last section above is self explanatory.
To view a live Demo : Click Here!
To Download the script above : Click Here!
Recent Comments