Listing event records under a date

2 posts by 2 authors in: Forums > CMS Builder
Last Post: April 2, 2013   (RSS)

By cjpritchard - April 1, 2013

Hello,

I'm trying to create a simple list of calendar events, but I'm having a couple of issues. Right now I have this foreach statement listing my events:

--------------------------------------------------------

            <?php foreach ($calendar_eventsRecords as $record): ?>
                <p><strong><?php echo date("l, F j", strtotime($record['date'])) ?></strong> <br/>
          
                <?php echo date("g:i a", strtotime($record['date'])) ?> (<?php echo $record['duration:label'] ?>) - <a href="#" class="tooltip" title="<?php echo $lessonsRecord['content']; ?> <?php echo htmlencode($record['content']) ?>"><?php echo $record['title:label'] ?></a></p>
        
            <?php endforeach ?>

--------------------------------------------------------

This produces the output:

Friday, July 19
10:00 am (2 hours) - Event Name

Friday, July 19
6:00 pm (2 hours) - Event Name

Saturday, July 27
10:00 am (2 hours) - Event Name

etc.

This is the output I need, with events listed under the date without the date repeated.

Friday, July 19
10:00 am (2 hours) - Event Name
6:00 pm (2 hours) - Event Name

Saturday, July 27
10:00 am (2 hours) - Event Name

Can you please tell me how I can create a loop for the events after the date output?

Thanks,Chris

By Djulia - April 2, 2013 - edited: April 2, 2013

Hello,

Here an approach, it is proposed at the origin by Damon.
http://www.interactivetools.com/forum/forum-posts.php?postNum=2216242#post2216242


<?php foreach ($calendar_events as $record): ?>
<?php $date = date("Y-m", strtotime($record['date'])); ?>
<?php if (@$lastDate != $date): ?>
<?php endif ?>

    <?php $dateHour = date("Y-m-d", strtotime($record['date'])); ?>
    <?php if (@$lastDateHour != $dateHour): ?>
    <br />
    <b><?php echo date("l, F j", strtotime($record['date'])); ?></b>
    <br />
    <?php endif ?>

  
       <?php echo date("g:i a", strtotime($record['date'])) ?> 
          (<?php echo $record['duration:label'] ?>) - <a href="#" class="tooltip" title="<?php echo $lessonsRecord['content']; ?> <?php echo htmlencode($record['content']) ?>"><?php echo $record['title:label'] ?></a><br />

    <?php $lastDateHour = $dateHour; ?>

<?php $lastDate = $date; ?>
<?php endforeach; ?>

You must use :

'orderBy' => 'date DESC',

Hope that helps!

Djulia