Alternating row colours

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.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists

Leave a Reply