Posted By

andreiabohner on 12/29/09


Tagged

css class php table html zebra


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

spf13
BrianCoyDesign


Zebra Table


 / Published in: PHP
 

  1. <html>
  2. <head>
  3. <title>zebra table</title>
  4. <style type="text/css">
  5. #mytable tbody tr.even td{
  6. background-color: #d3ecf5;
  7. }
  8. #mytable tbody tr.odd td{
  9. background-color: #fff;
  10. }
  11. </style>
  12. <body>
  13. <table id='mytable'>
  14. <tbody>
  15. <?php foreach($myData as $i=>$data): ?>
  16. <tr class="<?php echo fmod($i, 2) ? 'even' : 'odd' ?>">
  17. <td>
  18. <?php echo $data->getName(); ?>
  19. </td>
  20. </tr>
  21. <?php endforeach; ?>
  22. </tbody>
  23. </table>
  24. </body>
  25. </html>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: MMDeveloper on December 30, 2009

you can also just do

Posted By: MMDeveloper on December 30, 2009

echo ($i % 2) ? 'even' : 'odd';

You need to login to post a comment.