Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Alternating row colors in html table from xml datasource with php
- <?php
- // load SimpleXML
- $books = new SimpleXMLElement('books.xml', null, true);
- echo <<<EOF
- <table>
- <tr>
- <th>Title</th>
- <th>Author</th>
- <th>Publisher</th>
- <th>Price at Amazon.com</th>
- <th>ISBN</th>
- </tr>
- EOF;
- foreach($books as $book) // loop through our books
- {
- echo <<<EOF
- <tr>
- <td>{$book->title}</td>
- <td>{$book->author}</td>
- <td>{$book->publisher}</td>
- <td>${$book->amazon_price}</td>
- <td>{$book['isbn']}</td>
- </tr>
- EOF;
- }
- echo '</table>';
- ?>
- for($i=0;$i<6;$i++)
- {
- if($i % 2)
- {
- // even
- }else{
- // odd
- }
- }
- <?php
- // load SimpleXML
- $books = new SimpleXMLElement('books.xml', null, true);
- echo <<<EOF
- <table>
- <tr>
- <th>Title</th>
- <th>Author</th>
- <th>Publisher</th>
- <th>Price at Amazon.com</th>
- <th>ISBN</th>
- </tr>
- EOF;
- $even = true;
- foreach($books as $book) // loop through our books
- {
- $class = $even ? 'even' : 'odd';
- $even = $even ? false : true;
- echo <<<EOF
- <tr class="$class">
- <td>{$book->title}</td>
- <td>{$book->author}</td>
- <td>{$book->publisher}</td>
- <td>${$book->amazon_price}</td>
- <td>{$book['isbn']}</td>
- </tr>
- EOF;
- }
- echo '</table>';
- ?>
Add Comment
Please, Sign In to add comment