I am Abby
05-10-2010, 04:03 PM
I have a page that has a default message unless you change it. So when there's only one record in the xml you will see the default...but it you add a record the page will display that.
So I want my page to only print the last record in the xml.
The xml
<myusers>
<messages>
<id>1</id>
<message>words words and more words</message>
</messages>
</myusers>
<?php
$file = 'myxml.xml';
$xml = simplexml_load_file($file);
foreach($xml->children as messages)
{
$i = count ($xml->messages)-1;
echo $messages[$i]->message;
}
?>
I would thing this would print the last message only...but that's not what I'm getting.
So I want my page to only print the last record in the xml.
The xml
<myusers>
<messages>
<id>1</id>
<message>words words and more words</message>
</messages>
</myusers>
<?php
$file = 'myxml.xml';
$xml = simplexml_load_file($file);
foreach($xml->children as messages)
{
$i = count ($xml->messages)-1;
echo $messages[$i]->message;
}
?>
I would thing this would print the last message only...but that's not what I'm getting.