List upcoming events only
24 posts by 7 authors in: Forums > CMS Builder
Last Post: February 24, 2015 (RSS)
Hi
Is there any way to list the next upcoming event only. I have a series of events, and am using the "date" field, but how would I get upcoming date only, not dates that have already passed?
I know that
// load records from 'upcoming_events'
list($upcoming_eventsRecords, $upcoming_eventsMetaData) = getRecords(array(
'tableName' => 'upcoming_events',
'limit' => '1',
'loadUploads' => true,
'allowSearch' => false,
));
but haven't found anything on the forum to only show forthcoming dates.
Any ideas?
Thanks
Hey degreesnorth,
You just need to add a where statement that tells your getRecords function to return records that are greater than the current date:
//Get current date 1 second before midnight
$today = date('Y-m-d 23:59:59');
// load records from 'upcoming_events' that have a date greater than 1 second before midnight today.
list($upcoming_eventsRecords, $upcoming_eventsMetaData) = getRecords(array(
'tableName' => 'upcoming_events',
'where' => "`date` > '$today'",
'limit' => '1',
'loadUploads' => true,
'allowSearch' => false,
));
Thanks!
Greg
PHP Programmer - interactivetools.com
Hi degreesnorth,
Sorry I didn't see this.
It's(relatively) easy to add more complex functionality to the equation.
Lets say you wanted to show only this weeks upcoming events as a group.
You might use something like:
<?php
list($e_blast_events_noticeRecords, $e_blast_events_noticeMetaData) = getRecords(array(
'tableName' => 'e_blast_events_notice',
'where' => '((NOW() + INTERVAL 7 DAY) >= opening_reception_date_and_start_time AND opening_reception_date_and_start_time >= TIMESTAMP(CURDATE(), "00:00:00")) OR ((NOW() + INTERVAL 7 DAY) >= event_start_date AND event_start_date >= TIMESTAMP(CURDATE(), "00:00:00")) AND apbc_event != 1',
'orderBy'=> 'neverRemove ASC, event_start_date ASC',
));
?>
To filter those records.
There are other time related 'recipes' in the CMSB Cookbook http://www.thecmsbcookbook.com
Best,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By proba - February 13, 2015
Hello,
just want to ask is it possible to show results only from next seven days based on only date field. I mean today + next seven days only with date field?
Cheers
By claire - February 16, 2015
Hi there - yes, you can change the where clause to something like this:
<?php
list($e_blast_events_noticeRecords, $e_blast_events_noticeMetaData) = getRecords(array(
'tableName' => 'e_blast_events_notice',
'where' => 'date <= ((NOW() + INTERVAL 7 DAY) AND date >= NOW()',
));
?>
Claire Ryan
interactivetools.com
Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By proba - February 16, 2015
i got this error - "MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY dragSortOrder' at line 4"
By claire - February 16, 2015
I'm afraid you can't use this as is - it needs to be adjusted for your particular sections. Can you show me exactly what your getRecords query looks like?
Claire Ryan
interactivetools.com
Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Hello. Can you give me the 'where' statement if I need to show Listings from the current date to the last 7 days previously posted?
So I need to show the last 7 days Listings up until the current date. Thank you.