Grouping listings by month with header

4 posts by 3 authors in: Forums > CMS Builder
Last Post: November 3, 2008   (RSS)

By gkornbluth - October 26, 2008

I have a list of events that are pulled from a multi record editor and displayed on a listings page, sorted by date.

http://98.131.167.226/happenings.php

I’d like to be able to group the listings by month (in ascending order) with a “month” heading (probably an image) at the top of each month’s group.

If there are no listings for a particular month then no heading would be shown.

Anyone have an elegant solution?

Sorry, I just can’t seem to get my head around this one.

Thanks

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Grouping listings by month with header

By Kenny - October 26, 2008 - edited: October 26, 2008

Here's one built in a table you could use:

You'll need to replace my code with your code -

<table>
<?php
$lastCategory = "";
foreach ($eventRecords as $record):
$showHeader = false;
if ($record['month'] != $lastCategory) {
$lastCategory = $record['month'];
$showHeader = true;
}
?>
<?php if ($showHeader): ?>
<tr>
<td><?php echo $record['month'] ?></td>
</tr>
<?php endif ?>
<tr>
<td><?php echo $record['title'] ?></td>
</tr>
<tr>
<td><?php echo $record['content'] ?></td>
</tr>
<?php endforeach; ?>

</table>


Hope that helps -

Kenny

Re: [Judis] Grouping listings by month with header

By gkornbluth - November 3, 2008

Thanks for finding this.

I'll give it a try along with Kenny's ideas and let you know how it works out.

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php