Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $fetchEvents = $contentDB->query("SELECT id, title, description, dateStart, dateEnd, timeStart, timeEnd,
- YEAR(dateStart) AS year, MONTH(dateStart) AS month, MONTHNAME(dateStart) AS monthName
- FROM events_general ORDER BY dateStart");
- $prevYear = '';
- $prevMonth = '';
- while ($event = $fetchEvents->fetch())
- {
- $title = $event['title'];
- $description = $event['description'];
- $dateStart = $event['dateStart'];
- $month = $event['monthName'];
- $year = $event['year'];
- if ($year <> $prevYear) {
- // if a new year we definitely need to close the previous accordion div
- // unless it's the first iteration
- if ($prevMonth) {
- echo '</div><!-- close accordion div -->';
- }
- echo "<p><strong>$year</strong>\n";
- }
- if ($year <> $prevYear || $month <> $prevMonth) {
- // if new month but not new year close accordion
- if ($year == $prevYear) {
- echo '</div><!-- close accordion div -->';
- }
- echo "<p>$monthListing</p>\n";
- echo "<div class=\"accordion\">\n";
- }
- echo "<h3><a href=\"#\">$title - $dateStart</a></h3>\n<div>\n$description \n</div>\n";
- $prevYear = $year;
- $prevMonth = $month;
- }
- // add final closing div here
- echo '</div><!-- close accordion div -->';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement