i am running a foreach loop to get data from an xml file. the xml file has the same date listed several times, each with different data. what i need to do is show each date only once.
basicly i need the foreach loop to show the first date (object) on the first loop. if the date (object) is the same on the second, third, fourth loop, etc. then skip that loop and move to the next where the date (object) is not the same. here is what i have now:
$dateResults = $xml->xpath('/rtnshowtime/filmtitle/show[preceding-sibling::shortname="AGOODDAYTODIEHARD"]');
foreach ($dateResults as $dateResult) {
print_r($dateResult->date);
echo "<br>";
}
that produces:
SimpleXMLElement Object ( [0] => 02152013 )
SimpleXMLElement Object ( [0] => 02152013 ) <-- this one needs to be skipped
SimpleXMLElement Object ( [0] => 02152013 ) <-- this one needs to be skipped
SimpleXMLElement Object ( [0] => 02162013 )
SimpleXMLElement Object ( [0] => 02162013 ) <-- this one needs to be skipped
SimpleXMLElement Object ( [0] => 02162013 ) <-- this one needs to be skipped
SimpleXMLElement Object ( [0] => 02162013 ) <-- this one needs to be skipped
SimpleXMLElement Object ( [0] => 02162013 ) <-- this one needs to be skipped
SimpleXMLElement Object ( [0] => 02172013 )
SimpleXMLElement Object ( [0] => 02172013 ) <-- this one needs to be skipped
SimpleXMLElement Object ( [0] => 02172013 ) <-- this one needs to be skipped
SimpleXMLElement Object ( [0] => 02172013 ) <-- this one needs to be skipped
SimpleXMLElement Object ( [0] => 02172013 ) <-- this one needs to be skipped
SimpleXMLElement Object ( [0] => 02182013 )
SimpleXMLElement Object ( [0] => 02182013 ) <-- this one needs to be skipped
SimpleXMLElement Object ( [0] => 02192013 )
SimpleXMLElement Object ( [0] => 02192013 ) <-- this one needs to be skipped
SimpleXMLElement Object ( [0] => 02202013 )
SimpleXMLElement Object ( [0] => 02202013 ) <-- this one needs to be skipped
SimpleXMLElement Object ( [0] => 02212013 )
SimpleXMLElement Object ( [0] => 02212013 ) <-- this one needs to be skipped
ok, here's what i have opted for.
$shortname = $_GET['shortname'];
$dateURL = $_GET['date'];
$use_errors = libxml_use_internal_errors(true);
$xml = simplexml_load_file('XML/showtimes.xml');
if (!$xml) {echo "NO XML loaded<br>";}else{echo "XML IS loaded<br>";}
$results = $xml->xpath('/rtnshowtime/filmtitle[child::shortname="'.$shortname.'"]');
foreach ($results as $result) {
echo "showtimes for ".$dateURL."<br>";
foreach ($result->show as $result2) {
if ($result2->date == $dateURL) {
echo " -".$result2->time."- ";
}
}
}
that produces this for example:
showtimes for 02152013
-1300- -1400- -1500- -1600- -1700-
i use $_GET to get the date and shortname from the URL, then i use the shortname to decide which movie inside the xml that i will be dealing with. i then produce that as a result with the first foreach. i then run a second foreach within the first foreach specifically dealing with the child element that contains the dates and times. i then use an if statement to segregate which date i will be dealing with based on the URL. because of that if statement, i can then echo all of the times within that result where the sibling dates are the same. i would like to echo the times such as: 1300, 1400, 1500, 1600 with no comma following the last time, but i dont know how to do that. i tried using implode(), but because each time echo is inside an if statement it's an object instead of array results. i assume that... i'm not extremely familiar with the terminology. i have instead opted for a space and - before each time and a - and space after each time. it will have to work for now. :)
thanks to all of you guys for your assistance! stackoverflow ROCKS!!!