Show Future Dates

8 posts by 3 authors in: Forums > CMS Builder
Last Post: January 8, 2013   (RSS)

By dlsweb - December 12, 2012

How would I code below to only show events that are today and the future? Tks

<?php foreach ($coming_eventsRecords as $record): ?>
<p class="article_text"><strong><?php echo date("D, M j Y", strtotime($record['date'])) ?> -
<?php echo htmlencode($record['event_name']) ?></strong><br/>
<?php echo htmlencode($record['location']) ?><br/>
<?php echo htmlencode($record['event_description']) ?>  

<?php if ($record['contact_name']): ?>Contact <?php echo htmlencode($record['contact_name']) ?>, <?php endif ?>
<?php if ($record['contact_email']): ?><a href="mailto:<?php echo htmlencode($record['contact_email']) ?>">eMail</a>, <?php endif ?>
<?php if ($record['contact_phone']): ?>Phone <?php echo htmlencode($record['contact_phone']) ?>  <?php endif ?>
<?php if ($record['link_for_more']): ?> <a href="<?php echo htmlencode($record['link_for_more']) ?>">See More</a><?php endif ?>
</p>
<?php endforeach ?>

<?php if (!$coming_eventsRecords): ?>
No records were found!<br/><br/>
<?php endif ?>

By gregThomas - December 13, 2012 - edited: December 13, 2012

Hi,

Are you using a getRecords function to retrieve your records? If you are then easiest way to do this is to add a where statement that will only retrieve records that are newer than the current date:

$date = date('Y-m-d 00-00-00');
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'where' => "date >= '$date'",
'allowSearch' => false,
));


The date will have to be stored in a date field type in the section for this to work, but looking at your code below I think this is how you have it set up.

This is just an example, so you will have to modify the code so that it works with yours.

Let me know if you need something different.

Thanks!

Greg Thomas







PHP Programmer - interactivetools.com

By dlsweb - December 13, 2012

Thanks, but I have no clue where to insert in my code. ??

By dlsweb - December 15, 2012

thank you,
I inserted line but does not work and shows
Notice: Undefined variable: date in /home/bainbrid/public_html/events/index.php on line 39

file uploaded as txt
Attachments:

index_001.txt 3K

Sorry, I forgot to mention that you also need to include the code that sets the the $date variable. I've modified your code, and attached it to this post.

So the PHP code at the top of the page should look like this:
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

// load viewer library
$libraryPath = 'ca/lib/viewer_functions.php';
$dirsToCheck = array('/home/bainbrid/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

//Get the current date in SQL date format
$date = date('Y-m-d 00-00-00');


// load records from 'coming_events'
list($coming_eventsRecords, $coming_eventsMetaData) = getRecords(array(
'tableName' => 'coming_events',
'loadUploads' => true,
'allowSearch' => false,
'where' => "date >= '$date'",
));

?>

Thanks!

Greg
Greg Thomas







PHP Programmer - interactivetools.com
Attachments:

index_002.txt 4K

By dlsweb - December 17, 2012

Thanks So Much

Thanks, Greg. That was awesome.

Jeff Saitz