Jump to content

reading DOM to php table


myitalan

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/265829-reading-dom-to-php-table/
Share on other sites

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!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.