I had some trouble wording the question, but I think I can explain it better once I show the code: This is my xml file (test.xml)
<?xml version="1.0" encoding="utf-8"?>
<root>
<entry id="1">
<post>05/12/2014 12:00:00</post>
<page>1</page>
<part>1</part>
<body>BODY TEXT 1</body>
</entry>
<entry id="2">
<post>05/14/2014 12:00:00</post>
<part>1</part>
<page>2</page>
<body>BODY TEXT 2</body>
</entry>
</root>
This is my PHP code (call.php)
<?php
if(isset($_GET['p']))
{
$p=$_GET['p'];
echo $p . "<br>";
$xml=simplexml_load_file("test.xml");
$day=$xml->entry[$p]->post;//<-----------PROBLEM AREA
$post=strtotime("$day");
echo $post . "<br>";
echo time() . "<br>";
if(time() >= $post)
{
echo $xml->entry[$_GET['p']]->page . "<br>";
echo $xml->entry[$_GET['p']]->part . "<br>";
}
}else{
echo "<p>Main Page Stuff</p>";
}
?>
The problem I am having is with the $day variable. If I replace [$p] with [1] or [0], it runs perfectly, but I need to have it called with a variable so I can change what part of the XML file is loaded depending on the query string, currently '?p=1'.
The echo $p results prints out 1 or 0 depending on what I put into the URL, so the $_GET is working properly, but if I put either $p or $_GET into entry[] it gives the error
Notice: Trying to get property of non-object in C:\wamp\www\xmltest\call.php on line 20
(line 20 is the one marked 'PROBLEM AREA')
is there any way to fix this problem so I can call either the first or the second depending on the query string?
var_dump($xml);give you? Is there an entry array?object(SimpleXMLElement)[1] public 'entry' => array (size=2) 0 => object(SimpleXMLElement)[2] public '@attributes' => array (size=1) ...Is the result fromvar_dump($xml);