Advertisement
kremisoski

Possible Month / Event Fix I need.

Jul 31st, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. $fetchEvents = $contentDB->query("SELECT id, title, description, dateStart, dateEnd, timeStart, timeEnd,
  2. YEAR(dateStart) AS year, MONTH(dateStart) AS month, MONTHNAME(dateStart) AS monthName
  3. FROM events_general ORDER BY dateStart");
  4.  
  5. $prevYear = '';
  6. $prevMonth = '';
  7.  
  8. while ($event = $fetchEvents->fetch())
  9. {
  10.     $title = $event['title'];
  11.     $description = $event['description'];
  12.     $dateStart = $event['dateStart'];
  13.     $month = $event['monthName'];
  14.     $year = $event['year'];
  15.  
  16.     if ($year <> $prevYear) {
  17.         // if a new year we definitely need to close the previous accordion div
  18.         // unless it's the first iteration
  19.         if ($prevMonth) {
  20.             echo '</div><!-- close accordion div -->';
  21.         }
  22.         echo "<p><strong>$year</strong>\n";
  23.     }
  24.     if ($year <> $prevYear || $month <> $prevMonth) {
  25.         // if new month but not new year close accordion
  26.         if ($year == $prevYear) {
  27.             echo '</div><!-- close accordion div -->';
  28.         }
  29.         echo "<p>$monthListing</p>\n";
  30.         echo "<div class=\"accordion\">\n";
  31.     }
  32.  
  33.     echo "<h3><a href=\"#\">$title - $dateStart</a></h3>\n<div>\n$description \n</div>\n";
  34.  
  35.     $prevYear = $year;
  36.     $prevMonth = $month;
  37. }
  38. // add final closing div here
  39. echo '</div><!-- close accordion div -->';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement