xml - PHP SimpleXML startdate in given date range -
i have problems events xml-file startdate between given date range.
my xml file looks this:
<events> <event_data> <id>1</id> <startdate realdate="2013-08-06">1375740000</startdate> <enddate realdate="2013-08-13">1376344800</enddate> </event_data> <event_data> <id>2</id> <startdate realdate="2013-08-10">1376085600</startdate> <enddate realdate="2013-08-17">1376690400</enddate> <event_data> <event_data> <id>3</id> <startdate realdate="2013-08-17">1376690400</startdate> <enddate realdate="2013-08-24">1377295200</enddate> </event_data> <event_data> <id>4</id> <startdate realdate="2013-08-24">1377295200</startdate> <enddate realdate="2013-09-07">1378504800</enddate> <event_data> <event_data> <id>5</id> <startdate realdate="2013-08-25">1377381600</startdate> <enddate realdate="2013-09-08">1378591200</enddate> </event_data> <event_data> <id>6</id> <startdate realdate="2013-09-15">1379196000</startdate> <enddate realdate="2013-09-23">1379887200</enddate> <event_data> <event_data> <id>7</id> <startdate realdate="2013-10-26">1382738400</startdate> <enddate realdate="2013-11-02">1383346800</enddate> </event_data> <event_data> <id>8</id> <startdate realdate="2013-11-10">1384038000</startdate> <enddate realdate="2013-11-15">1384470000</enddate> <event_data> <event_data> <id>9</id> <startdate realdate="2014-01-11">1389394800</startdate> <enddate realdate="2014-01-18">1389999600</enddate> </event_data> <event_data> <id>10</id> <startdate realdate="2014-01-19">1390086000</startdate> <enddate realdate="2014-01-24">1390518000</enddate> <event_data> </events>
my php code this:
<form action="" method="post"> <div id="slider-range"></div> <input type="text" name="startdate" style="margin:40px 0 0"> <input type="text" name="enddate" style="margin:40px 0 0"> <input type="submit" name="submitclub" value="submit" /> </form> <?php ?> <div id="eventlist"> <?php $sxe = simplexml_load_file('events.xml'); if($sxe) { if(isset($_post['submitclub'])) { $varstart = $_post['startdate']; $varend = $_post['enddate']; if($varstart){ $start = strtotime($varstart); $end = strtotime($varend); $xpath = sprintf( '//event_data[ (%1$d >= startdate , %2$d <= enddate) or (%1$d <= enddate , %2$d >= startdate) ]', strtotime($varstart), strtotime($varend) ); foreach($sxe->xpath($xpath) $event){ echo $event->id, php_eol . '<br>'; } } } else { echo 'keine events'; } } else { echo '<p>die datei konnte nicht geƶffnet werden</p>'; } ?> </div>
with dates start , ends during given date range want display events start during given date range.
so lets want display events start between august 12, 2013 , august 24, 2013, events should displayed:
3 4
if date range between september 15, 2013 , november 10, 2013 these events should displayed
6 7 8
i appreciate :)
edited: works now. change
(%1$d >= startdate , %2$d <= enddate) or (%1$d <= enddate , %2$d >= startdate)
to
(%1$d <= startdate , %2$d >= startdate)
i found solution problem above. changed
(%1$d >= startdate , %2$d <= enddate) or (%1$d <= enddate , %2$d >= startdate)
to
(%1$d <= startdate , %2$d >= startdate)
Comments
Post a Comment