This should be simple but I guess I’m hitting a mental block- I have a mysql array containing a date and a name for each event. I want a header and a footer for each separate “day.” So it would look something like this:
New Day
Event 1
Event 2
End Day
New Day
Event 3
Event 4
End Day
My code so far looks like this, but I can only get the header to show up:
$day = null;
foreach($events as $event) {
if ($day != date('d', strtotime($event->date))) {
echo "New day:<br />";
}
echo $event->name;
$day = date('d', strtotime($event->date));
}
So basically I loop through and compare “$day” to $event->day…This solves the header, but what should I do to get the footer to show up?
You can do the trick with just a couple of small additions:
The idea here is that “end day” always precedes “new day”, with two exceptions:
The two conditions correspond directly to these two circumstances: if you have seen any “new day” outputs at all (can be checked very conveniently) then you want to precede “new day” with “end day” and also wrap up the output in the same manner.