Show Future Dates

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

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 gregThomas - December 14, 2012

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

By gregThomas - December 17, 2012

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

By jeffsaitz - January 8, 2013

Thanks, Greg. That was awesome.

Jeff Saitz