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 dlsweb - December 13, 2012

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

At the top of your page you should see some code that looks a little bit like this:

<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('W:/g/greg.com/htdocs/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }


// load records from 'news'
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'allowSearch' => false,
'debugSql' => true
));


In the getRecords function there should be an array, and you need to add this line too it:

'where' => "date >= '$date'",

If your still having trouble, would it be possible to attach your current file to a post so I can have a look at it for you?

Thanks!

Greg
Greg Thomas







PHP Programmer - interactivetools.com

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