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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.