Where's my mistake?
3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 6, 2013 (RSS)
By Toledoh - May 6, 2013
This is bugging me... why is it breaking the table after 2 rows?
http://www.perisherxcountry.org/pages.php?LOCAL-EVENT-CALENDAR-29
<?php foreach ($eventsRecords as $record): ?>
<?php //** DEFINE $DATE AS NEW VARIABLE FOR DATE IN RECORD: ?>
<?php $date = date("F Y", strtotime($record['date'])); ?>
<?php //** DISPLAY DATE IF DIFFERENT FROM LAST DATE ?>
<?php if (@$lastDate != $date): ?>
<div class="calendar">
<h2><?php echo $date ?></h2>
<table>
<thead>
<tr>
<th>Date</th>
<th>Event</th>
<th>Contact</th>
<th>Entry</th>
</tr>
</thead>
<tbody>
<?php endif ?>
<?php //** SHOW WHAT EVER OTHER CONTENT I WANT FROM RECORDS ?>
<tr>
<td><?php echo date("D F", strtotime($record['date'])) ?><br /><?php echo date("g:i a", strtotime($record['date'])) ?></td>
<td><?php echo htmlencode($record['event']) ?><br />
Meet: <?php echo htmlencode($record['meeting_place']) ?></td>
<td><?php echo htmlencode($record['contact_name']) ?><br />Ph: <?php echo htmlencode($record['contact_phone']) ?></td>
<td>
<?php if ($record['online_entry']): ?>
<a href="<?php echo htmlencode($record['online_entry']) ?>" target="_blank">Online »</a><br/>
<?php endif ?>
<?php if ($record['pdf_form']): ?>
<?php foreach ($record['pdf_form'] as $index => $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>">Download »</a><br />
<?php endforeach ?>
<?php endif ?>
<?php if ($record['enter_on_the_day']): ?>On the day<?php endif ?>
</td>
</tr>
<?php //** END $LASTDATE VARIABLE ?>
<?php if (@$lastDate == $date): ?>
</tbody>
</table>
</div>
<?php endif ?>
<?php //** SET $LASTDATE VARIABLE ?>
<?php $lastDate = $date; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
Tim (toledoh.com.au)
By Jason - May 6, 2013
Hi Tim,
The issue is this if block here:
<?php if (@$lastDate == $date): ?>
</tbody>
</table>
</div>
<?php endif ?>
What this is trying to do is that every time the last date is the same as the current date, close out the table. But the table doesn't get re-opened unless the dates are different. To fix this, remove this block from the bottom of the foreach loop and change the block at the top like this:
<?php if (@$lastDate != $date): ?>
<?php if (@$lastDate): ?>
</tbody>
</table>
</div>
<?php endif ?>
<div class="calendar">
<h2><?php echo $date ?></h2>
<table>
<thead>
<tr>
<th>Date</th>
<th>Event</th>
<th>Contact</th>
<th>Entry</th>
</tr>
</thead>
<tbody>
<?php endif ?>
This should close the last table before it reopens the next. This won't execute during the first iteration of the loop as $lastDate won't have a value.
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/
By Toledoh - May 6, 2013
So clear after you point it out. Thanks Jason!
Tim (toledoh.com.au)