Displaying an include based on specific values

6 posts by 3 authors in: Forums > CMS Builder
Last Post: March 12, 2012   (RSS)

I have a site where my client can put events into one of four time segments: 10:15am - 11:15am, 11:30am - 12:30pm, 1:45pm - 2:45pm, or 3:00pm - 4:00pm.

I'd like to present these on a page listed under subheadings for each time segment, so the events taking place at 10:15am - 11:15am would show up under that subheading, and so on.

The live page is here - http://www.springflingevent.ca/sessions2.php - and the session details are displayed via an include, _include-sessions-segment.php.

Every session is being displayed under each time segment, rather than being sorted. Any suggestions on how to get this to work properly, please?

Also, once that's working, how do I get this to display in two columns?

======

_include-sessions-segment.php code:

<?php foreach ($sessions_detailsRecords as $record): ?>
<h2 class="h2Smaller"><strong><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?> &raquo;</a></strong></h2>
<p>Presented by <?php echo $record['presenter_s'] ?><br />
Time: <?php echo $record['time'] ?></p></td>
<?php endforeach; ?>

======

This is the code in sessions2.php that displays the include for 10:15am - 11:15am:

<?php
$_REQUEST['time']="10:15am - 11:15am";
include("_include-sessions-segment.php");
?>

======

Thank you!
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] Displaying an include based on specific values

By Jason - March 9, 2012

Hi Nigel,

You can put in an if statement to skip any records that doesn't match the current time period being output:

<?php foreach ($sessions_detailsRecords as $record): ?>

<?php if ($record['time'] != @$_REQUEST['time']) { continue; } ?>

<h2 class="h2Smaller"><strong><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?> &raquo;</a></strong></h2>
<p>Presented by <?php echo $record['presenter_s'] ?><br />
Time: <?php echo $record['time'] ?></p></td>
<?php endforeach; ?>



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/

Re: [Jason] Displaying an include based on specific values

Perfect! Thanks, Jason.

http://www.springflingevent.ca/sessions2.php

Any idea how I get this to show up in two columns, please?
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [gkornbluth] Displaying an include based on specific values

Thanks for the advice, Jerry. I didn't go for the double columns in the end, sticking with just one.

However, I did use Jason's code to help create a form with drop down menus, based on the same data entered into CMSB. This is the page Jason helped me with - http://www.springflingevent.ca/sessions.php - and this is the form page, which uses some of the same records - http://www.springflingevent.ca/register.php.

Here's the code for the include that creates the drop down menus:

<select name="select">
<option>Please choose a session:</option>
<?php foreach ($sessions_detailsRecords as $record): ?>
<?php if ($record['time'] != @$_REQUEST['time']) { continue; } ?>
<option value="TICKETS FOR <?php echo $record['title'] ?>"><?php echo $record['title'] ?></option>
<?php endforeach; ?>
</select>

Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] Displaying an include based on specific values

Thanks Nigel,

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