unistake Posted May 17, 2014 Share Posted May 17, 2014 Hi guys, I am trying to echo multiple calendar events from a mysql table and order them by the date column. There are several events on each day so I am trying to echo the date once then list the associated events under that date. Such as 2014-05-10 Event 1, event 2, event 3 2014-05-11 Event 1, event 2, event 3 instead of 2014-05-10 event 1, 2014-05-10 event 2, 2014-05-10 event 3, 2014-05-11 event 1 etc... This is my coding so far: while($row = mysqli_fetch_assoc($result)) { $dutydate = $row['MyDate']; if($dutydate != $previousdate) { echo $dutydate.'<br />'; } elseif(!empty($dutydate)) { echo $dutydate.'<br />'; } echo $event1.' | '.$event2.' | '.$event3.'<br />'; $previousdate = $dutydate; } ?> Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted May 17, 2014 Solution Share Posted May 17, 2014 try $previousdate=''; $events = array(); while($row = mysqli_fetch_assoc($result)) { $dutydate = $row['myDate']; if($dutydate != $previousdate) { if ($previousdate) { echo $previousdate . '<br>' . join(", ", $events) . '<br><br>'; } $events = array(); $previousdate = $dutydate; } $events[] = $row['event_name']; } echo $previousdate . '<br>' . join(", ", $events) . '<br><br>'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.