I'm trying to be able to count total events for a given day (today) for a specific venue. Using 24 hour time, I tried to find last event of the day within the foreach loop and then when the end_time of last event of the day is less than now, show text, "All scheduled events have concluded for today."
my problem is that the xml data includes all events in all rooms for 14 days and I'm not getting the correct count. I have a few if statements within the foreach to whittle it down....
if xml space id == room id, then if xml event start_date equals today, then if ($i < $numItems) if event end time is greater than now, show those events
I need the count of records when those conditions are met...when events are for today's date and in the same room as the roomID that gets passed thru url. Putting my $numItems = $count($arr) before the foreach counts too many records and putting a count within foreach always returns only count of 1.
$arr = $this->data['events'];
$numItems = count($arr);
$i = 1;
foreach ($arr as $key => $reservation){
if ((int)$reservation->space_reservation->space_id == $roomID)
{
//test today's date
$resDT = date('m/d/y',strtotime($reservation->reservation_start_dt));
if ($resDT == date('m/d/y'))
{
if ($i < $numItems)
{
$repst = substr($reservation->event_start_dt,11,5);
$repet = substr($reservation->event_end_dt,11,5);
if ( (date('H:i',strtotime($repet))) > (date('H:i')) )
{
echo '<h2>' .$reservation->event_name. '</h2> ';
echo '<span class="dates">' .date('m/d/y',strtotime($reservation->event_start_dt)). ' </span> ';
echo '<span class="times">' .date('g:i a',strtotime($repst)). ' - ';
echo date('g:i a',strtotime($repet)). '</span> ';
echo '<br />';
} // ends if event end date has passed
//echo '<span style="color:#FFF200;">'.$i.'</span>';
echo '<br />';
}
//if $i equals last record
elseif ($i === $numItems) {
// test if last event ends show
if ( (date('g:i a',strtotime($repet))) < (date('g:i: a')) ){
echo '<span style="color:#FFF200;">All scheduled meetings/events have concluded for today. </span><br /><br />';
}
}
$i++;
} // ends if
} // ends if
} // ends for each