1

I have a radio station site on localhost, and the pages are a series of include and requires - they work well.

However, on one page, a schedule one, I'm displaying within a DIV some data extracted from a SimpleXML document.

This is the PHP document's coding:

        <div class="itemheading"><h1><span>Programme Guide</span></h1></div>
        <div class="itembody">
          <div id="progdays">
                        <ul>
<li><a href="sunsch.php" title="Sunday">Sunday</a></li>
<li class="currentday"><a href="monsch.php">Monday</a></li>
<li><a href="tuesch.php" title="Tuesday">Tuesday</a></li>
<li><a href="wedsch.php" title="Wednesday">Wednesday</a></li>
<li><a href="thursch.php" title="Thursday">Thursday</a></li>
<li><a href="frisch.php" title="Friday">Friday</a></li>
<li><a href="satsch.php" title="Saturday">Saturday</a></li>                                             </ul>
          </div>
<?php
require("monsch.php");
?>
                                                            </div>

Here is the content of monsch.php:

        <?php

// set name of XML file
// normally this would come through GET
// it's hard-wired here for simplicity
$file = "monsched.xml";

// load file
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");
?> 

                            <dl class="standard">
                <dt><a href="<?php echo $xml->link; ?>" title="<?php echo $xml->show; ?>"><?php echo $xml->showtime; ?> - <?php echo $xml->show; ?></a></dt>
                <dd class="itemimg"><a href="<?php echo $xml->link; ?>" title="<?php echo $xml->show; ?>"><img src="<?php echo $xml->image; ?>" width="100" height="75" alt="<?php echo $xml->show; ?>" title="<?php echo $xml->show; ?>" /></a></dd>
                <dd class="itemdesc">
<?php echo $xml->showinfo; ?>
                </dd>
                <dd class="itemlink">
                  <a href="<?php echo $xml->link; ?>" title="<?php echo $xml->moreinfo; ?>"><span></span><?php echo $xml->moreinfo; ?></a>
                </dd>
              </dl>

It works well correctly using the echo() function of PHP, but how would I get the XML file to display more than one record from it.

Here's the XML content of monsched.xml:

<?xml version="1.0"?>
<prog>
    <link>presenter.php</link>
    <show>Johnny Doe</show>
    <image>johnny.jpg</image>
    <showtime>00:00</showtime>
    <showinfo>
        John Doe through the night
    </showinfo>
    <moreinfo>More about the show</moreinfo>
</prog>

I followed the tutorial at http://devzone.zend.com/article/651 (the Baz Luhrmann example at the end was what I was trying to emulate). and everything worked OK, except one problem.... how do I get the PHP file to, using SimpleXML, read from multiple records within the XML file.

If I have a lot of shows in it, how would I get it to extract all of them from the XML file like the format above.

These are the shows with descriptions and images:

01:00 Johnny Doe jdoe1.jpg
John Doe at night
06:00 Joe Smith smith1.jpg
John Smith in the morning
10:00 Mark Jones mj1.jpg
Mark plays hits
14:00 Matthew B
Matthew B
18:00 Non Stop Hits
Non-stop
20:00 Richard Roe
Richard Roe at night

All help is appreciated with this, I'm fairly new to SimpleXML, but trying to get the Baz Luhrmann example to work for multiple entries is tricky - anyone able to figure it out?

The tutorial was otherwise helpful, though, but didn't answer all my questions.

1 Answer 1

1

You need to put your xml into a foreach:

<?php
foreach($xml as $attr) {
  $attr->link;
}
?>

Without knowing more of your xml schema thats about all I can provide, but this should get you thinking down the right path.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.