myitalan Posted July 17, 2012 Share Posted July 17, 2012 Greetings, My apologies to my earlier post that was confusing as to what i was trying to do... this isn't a re-post but a new post with specific help request. i have an xml file formatted as follows: <?xml version="1.0" encoding="utf-8"?> <gallery> <images> <title>Title 1</title> <description>Title Decscription</description> <tmb>photoGallery/tmb1.jpg</tmb> <img>photoGallery/pic1.jpg</img> </images> <images> <title>Title 2</title> <description>Title 2 Description</description> <tmb>photoGallery/tmb2.jpg</tmb> <img>photoGallery/pic2.jpg</img> </images> </gallery> I am attempting to display in a table as such: <?php $dom = new DomDocument(); $dom -> load("playlist.xml"); $images = $dom->getElementsByTagName('images'); $counter = 0; // Set the entry counter echo( "<table>"); foreach($images as $node) { if ($counter % 4 == 0) { echo '<tr>'; } echo "<td>". $node -> textContent . "<td>"; if($counter % 4 == 0) { echo '</tr>'; } $counter++; // Increment the counter } echo( "</table>"); ?> But it crashes, even with forced errors... i just get a white screen. Any clue? Quote Link to comment https://forums.phpfreaks.com/topic/265829-reading-dom-to-php-table/ Share on other sites More sharing options...
myitalan Posted July 17, 2012 Author Share Posted July 17, 2012 Figured it out! Being that my request seemed to stump the masses below is how I did it <ul> <?php error_reporting(E_ALL); ini_set( 'display_errors','1'); $doc = new DOMDocument(); $doc->load( 'playlist.xml' ); $gallery = $doc->getElementsByTagName( "images" ); //Loop through each item foreach ($gallery as $images) { ?> <li> <table> <tbody> <tr> <td><b>Title:</b></td> <td><?php echo $images->getElementsByTagName('title')->item(0)->nodeValue; ?></td> </tr> <tr> <td><b>Description:</b></td> <td><?php echo $images->getElementsByTagName('description')->item(0)->nodeValue; ?></td> </tr> <tr> <td><b>Image:</b></td> <td><?php echo $images->getElementsByTagName('img')->item(0)->nodeValue; ?></td> </tr> </tbody> </table> </li> <?php } ?> </ul> 3 days and too many hours!! Quote Link to comment https://forums.phpfreaks.com/topic/265829-reading-dom-to-php-table/#findComment-1362224 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.