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; } ?> Link to comment https://forums.phpfreaks.com/topic/288555-simple-looping-problem/ Share on other sites More sharing options...
Barand Posted May 17, 2014 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>'; Link to comment https://forums.phpfreaks.com/topic/288555-simple-looping-problem/#findComment-1479823 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.