Upcoming Events Listings

2 posts by 2 authors in: Forums > CMS Builder
Last Post: May 31, 2010   (RSS)

By paulmac - May 31, 2010

Hi

I'm trying to build a simpe upcoming events system, with the content displayed something lik below:

November 2010
01/11/2010......Event Details
29/11/2010......Another Event

December 2010
01/12/2010......Event Details
29/12/2010......Another Event

I have no problem displaying each event, I just need some help displaying the Month and Year at the top of each month's listing. They should only display once for each month.

Any help would be appreciated.

Re: [paulmac] Upcoming Events Listings

By Jason - May 31, 2010

Hi,

First thing you need to do is when you select your records, to order them by their date:

<?php
list($eventRecords,$eventMetaData)=getRecords(array(
'tableName' => 'events',
'orderBy' => 'start_date'
));
?>


Next, use this code where you're outputting your records:
<?php $heading = ""; ?>
<?php foreach ($eventRecords as $event): ?>
<?php if($heading!=date("F Y",strtotime($event['start_date']))): ?>
<?php $heading=date("F Y",strtotime($event['start_date'])); ?>
<?php echo $heading; ?> <br />
<?php endif ?>
<?php echo date("d-m-Y",strtotime($event['start_date'])); ?> - <?php echo $event['title']; ?><br />
<?php endforeach ?>


For each record, it checks to see if the month and year have changed. If they have, they output the new heading. Of course, you'll need to change the names here to match what you have in your database.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/