PHP MySQL ebook
February 12, 2011 – 4:57 pm | No Comment

Hey everyone!!
With this section I hope to share with you resources which I have tried and valued
So you’re new to PHP and want to learn from scratch. Well I was in your position not too …

Read the full story »
SEO Tutorials

Need help with Search Engine Optimisation? This is the place to look for the latest tips and hints with the advice we offer. Keep an eye out here for the latest posts.

PHP Tutorials

Learn how to code with PHP to achieve your goal. In here I aim to show and teach you about little tips and tricks that should enhance your coding abilities

Flash Tutorials

Learn how to use Adobe Flash for your own purposes. Little tips and hints to help you along

Website Development

In here I aim to help you with developing your website from scratch. Come here for various tips and pieces of advice to help you build and improve your website.

Home » PHP Tutorials

Alternating row colours

Submitted by on July 29, 2007 – 3:16 pmNo Comment

Have you ever wanted to make a table with alternating row colours?

Well I did it for a site and thought it would be great to share it. Here

PHP:
  1. //connect to db and select table
  2. $db1 = mysql_connect("host", "user", "pass");
  3. mysql_select_db("$db",$db1);
  4. $table = "tablename"; //table name
  5.  
  6. $list = mysql_query("SELECT * FROM `$table` ORDER BY `coulmn_name` ASC "); // the SQL of the table you will show
  7. <h3>
  8. <p align="center">$table</p>
  9. </h3>
  10. "; //title for the page
  11. <table style="border: 1px solid black; font-family: Verdana; height: 110px;" border="0" cellspacing="1" cellpadding="2" width="500" align="center">'); //add the table
  12. <tbody>
  13. <tr align="center">
  14. <td><strong><span style="text-decoration: underline;">Date</span></strong></td>
  15. <td><strong><span style="text-decoration: underline;">description</span></strong></td>
  16. </tr>
  17. '); // top row with the titles
  18. while($get=mysql_fetch_array($list))
  19. {
  20. //chooses colous
  21. if ($color == "CCFFCC")
  22. {
  23. $color = "FFFFFF";//change the code
  24. }
  25. else
  26. {
  27. $color = "CCFFCC"; //change the code
  28. }
  29.  
  30. <tr align="center" bgcolor="#000000">
  31. <td>'. $get['Date'] .'</td>
  32. <td>'. $get['description'] .'</td>
  33. </tr>
  34. ')//add the contents
  35. }
  36. echo("</tbody></table>
  37. "); //finish the table
  38.  
  39. ?&gt;

VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

Popularity: unranked [?]

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.