I'm getting data from an xml file using php simplexml. I'm gettin the time and date of each showing of a film by splitting the TimeStamp in the Time node. Each loop brings out every date along with every time but if the showing is on more than once in the same day I want the date to be only shown once.
I thought of creating an array to then delete duplicates but that's where I'm having issues, I keep ending up creating a seperate array for each Time loop.You can see at the bottom the output I'd like. Thanks...file
<Event xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Attributes>
<EventAttribute>
<Name>Event Type</Name>
<Value>Cinema</Value>
</EventAttribute>
<EventAttribute>
<Name>Venue</Name>
<Value>Building 1</Value>
</EventAttribute>
</Attributes>
<Description />
<Duration>0</Duration>
<FirstInstance>2019-08-02T13:30:00</FirstInstance>
<Id>220002</Id>
<ImageUrl />
<LastInstance>2019-08-08T19:00:00</LastInstance>
<Name>Spider-Man: Far From Home (12a)</Name>
<OnSaleOnWeb>true</OnSaleOnWeb>
<ThumbnailUrl />
<Times>
<EventTime>
<Attributes>
<EventAttribute>
<Name>Venue</Name>
<Value> Building 1</Value>
</EventAttribute>
<EventAttribute>
<Name>Special Performance</Name>
<Value />
</EventAttribute>
</Attributes>
<Capacity>509</Capacity>
<EventInstanceId>376802</EventInstanceId>
<OnSaleOnWeb>true</OnSaleOnWeb>
<SeatsAvailable>345</SeatsAvailable>
<SeatsLocked>164</SeatsLocked>
<SeatsReserved>0</SeatsReserved>
<SeatsSelected>0</SeatsSelected>
<SeatsSold>0</SeatsSold>
<Time>2019-08-02T13:30:00</Time>
<WebInstanceId i:nil="true" />
</EventTime>
<EventTime>
<Attributes>
<EventAttribute>
<Name>Venue</Name>
<Value> Building 1</Value>
</EventAttribute>
<EventAttribute>
<Name>Special Performance</Name>
<Value />
</EventAttribute>
</Attributes>
<Capacity>509</Capacity>
<EventInstanceId>377002</EventInstanceId>
<OnSaleOnWeb>true</OnSaleOnWeb>
<SeatsAvailable>343</SeatsAvailable>
<SeatsLocked>164</SeatsLocked>
<SeatsReserved>0</SeatsReserved>
<SeatsSelected>0</SeatsSelected>
<SeatsSold>2</SeatsSold>
<Time>2019-08-02T19:00:00</Time>
<WebInstanceId i:nil="true" />
</EventTime>
<EventTime>
<Attributes>
<EventAttribute>
<Name>Venue</Name>
<Value> Building 1</Value>
</EventAttribute>
<EventAttribute>
<Name>Special Performance</Name>
<Value />
</EventAttribute>
</Attributes>
<Capacity>509</Capacity>
<EventInstanceId>376803</EventInstanceId>
<OnSaleOnWeb>true</OnSaleOnWeb>
<SeatsAvailable>345</SeatsAvailable>
<SeatsLocked>164</SeatsLocked>
<SeatsReserved>0</SeatsReserved>
<SeatsSelected>0</SeatsSelected>
<SeatsSold>0</SeatsSold>
<Time>2019-08-03T13:30:00</Time>
<WebInstanceId i:nil="true" />
</EventTime>
<EventTime>
<Attributes>
<EventAttribute>
<Name>Venue</Name>
<Value> Building 1</Value>
</EventAttribute>
<EventAttribute>
<Name>Special Performance</Name>
<Value />
</EventAttribute>
</Attributes>
<Capacity>509</Capacity>
<EventInstanceId>377003</EventInstanceId>
<OnSaleOnWeb>true</OnSaleOnWeb>
<SeatsAvailable>345</SeatsAvailable>
<SeatsLocked>164</SeatsLocked>
<SeatsReserved>0</SeatsReserved>
<SeatsSelected>0</SeatsSelected>
<SeatsSold>0</SeatsSold>
<Time>2019-08-03T19:00:00</Time>
<WebInstanceId i:nil="true" />
</EventTime>
<EventTime>
<Attributes>
<EventAttribute>
<Name>Venue</Name>
<Value> Building 1</Value>
</EventAttribute>
<EventAttribute>
<Name>Special Performance</Name>
<Value />
</EventAttribute>
</Attributes>
<Capacity>509</Capacity>
<EventInstanceId>376804</EventInstanceId>
<OnSaleOnWeb>true</OnSaleOnWeb>
<SeatsAvailable>345</SeatsAvailable>
<SeatsLocked>164</SeatsLocked>
<SeatsReserved>0</SeatsReserved>
<SeatsSelected>0</SeatsSelected>
<SeatsSold>0</SeatsSold>
<Time>2019-08-05T13:30:00</Time>
<WebInstanceId i:nil="true" />
</EventTime>
<EventTime>
<Attributes>
<EventAttribute>
<Name>Venue</Name>
<Value> Building 1</Value>
</EventAttribute>
<EventAttribute>
<Name>Special Performance</Name>
<Value />
</EventAttribute>
</Attributes>
<Capacity>509</Capacity>
<EventInstanceId>376805</EventInstanceId>
<OnSaleOnWeb>true</OnSaleOnWeb>
<SeatsAvailable>345</SeatsAvailable>
<SeatsLocked>164</SeatsLocked>
<SeatsReserved>0</SeatsReserved>
<SeatsSelected>0</SeatsSelected>
<SeatsSold>0</SeatsSold>
<Time>2019-08-06T13:30:00</Time>
<WebInstanceId i:nil="true" />
</EventTime>
</Times>
<WebEventId i:nil="true" />
</Event>
I'm using this php to get the data from the XML file:
<?php
$xml=simplexml_load_file("myxml.xl") or die("Error: Not Working");
foreach($xml->Times->EventTime as $Times) {
$filmdate =$Times->Time;
$shortdate = date("D d M",strtotime(date($filmdate)));
$filmtimenew = date("g.ia",strtotime(date($filmdate)));
if( strtotime($filmdate) > strtotime('now') ) {
echo "<span>" . $shortdate . "</span>";
echo "<a href='#'>" . $filmtimenew . "</a>";
echo "<br>";
}
}
?>
This is the output I'm getting:
Fri 02 Aug 1.30pm
Fri 02 Aug 7.00pm
Sat 03 Aug 1.30pm
Sat 03 Aug 7.00pm
Mon 05 Aug 1.30pm
But I want this without the duplicate date:
Fri 02 Aug 1.30pm 7.00pm
Sat 03 Aug 1.30pm 7.00pm
Mon 05 Aug 1.30pm
I did initially hide the duplicates with JQuery but I'd like to do it properly.