Hi
Continuing from a previous thread which became slightly off topic, and thanks to fretburner.
What I’m trying to do is filter the associative array so only the events from today onwards will be shown inside my foreach loop.
My code:
$queryEvents = " SELECT ID , DTEND , DTSTAMP , LOCATION , DTSTART , SUMMARY FROM events_test ORDER BY DTSTART ASC"; $resultEvents = $mysqli->query($queryEvents); $row_cnt = $resultEvents->num_rows;
$eventsArray = array();
while ($row = $resultEvents->fetch_assoc()) { $row['endTime'] = date('g:ia', strtotime($row['DTEND'])); $row['fullDate'] = date('l jS F Y', strtotime($row['DTSTART'])); $row['startTime'] = date('g:ia', strtotime($row['DTSTART'])); $eventsArray[] = $row; }
And further down the page I show the results which lists all the events from the DB, including out of date events:
foreach($eventsArray as $value){ echo "<li><a href='event/{$value['ID']}'> {$value['SUMMARY']}<br> {$value['LOCATION']}<br> {$value['startTime']} - {$value['endTime']}</a></li>"; }
I would like to filter this array so I only show events for today and any future upcoming events.
I have tried the below though returning array(0) ?
I am trying to query this filter based on $row['startTime']
a column every record has.
$today = new DateTime(); $current_events = array_filter($eventsArray, function($event) use ($today) { $event_start = $row['startTime']; return $event_start >= $today; }); var_dump($current_events);
Any ideas how to fix this and build the filter into my foreach?
My main goal is to have a list like below showing events in order under the date no older than today:
23rd June 1016
Event name
Event name
Event name
24th June 2016
Event name
Event name
Event name
Thank you,
Barry