Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 59 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. Alternating row colors in html table from xml datasource with php
  2. <?php
  3. // load SimpleXML
  4. $books = new SimpleXMLElement('books.xml', null, true);
  5.  
  6. echo <<<EOF
  7. <table>
  8.         <tr>
  9.                 <th>Title</th>
  10.                 <th>Author</th>
  11.                 <th>Publisher</th>
  12.                 <th>Price at Amazon.com</th>
  13.                 <th>ISBN</th>
  14.         </tr>
  15.  
  16. EOF;
  17. foreach($books as $book) // loop through our books
  18. {
  19.         echo <<<EOF
  20.         <tr>
  21.                 <td>{$book->title}</td>
  22.                 <td>{$book->author}</td>
  23.                 <td>{$book->publisher}</td>
  24.                 <td>${$book->amazon_price}</td>
  25.                 <td>{$book['isbn']}</td>
  26.         </tr>
  27.  
  28. EOF;
  29. }
  30. echo '</table>';
  31. ?>
  32.    
  33. for($i=0;$i<6;$i++)
  34.   {
  35.      if($i % 2)
  36.   {
  37.     // even
  38.   }else{
  39.     // odd
  40.   }
  41. }
  42.    
  43. <?php
  44. // load SimpleXML
  45. $books = new SimpleXMLElement('books.xml', null, true);
  46.  
  47. echo <<<EOF
  48. <table>
  49.     <tr>
  50.         <th>Title</th>
  51.         <th>Author</th>
  52.         <th>Publisher</th>
  53.         <th>Price at Amazon.com</th>
  54.         <th>ISBN</th>
  55. </tr>
  56.  
  57. EOF;
  58.  
  59. $even = true;
  60.  
  61. foreach($books as $book) // loop through our books
  62. {
  63.     $class = $even ? 'even' : 'odd';
  64.     $even = $even ? false : true;
  65.  
  66.     echo <<<EOF
  67.     <tr class="$class">
  68.             <td>{$book->title}</td>
  69.             <td>{$book->author}</td>
  70.             <td>{$book->publisher}</td>
  71.             <td>${$book->amazon_price}</td>
  72.             <td>{$book['isbn']}</td>
  73.     </tr>
  74.  
  75. EOF;
  76. }
  77. echo '</table>';
  78. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top