event signup date equal to or greater than now, otherwise do not show event signup
5 posts by 2 authors in: Forums > CMS Builder
Last Post: June 17, 2015 (RSS)
By Mikey - June 14, 2015
In response to: [url "http://www.interactivetools.com/forum/forum-posts.php?postNum=2234791#post2234791"]removeDate and mySQL count[/url], ...
I'm trying to show on event signups that have a date equal to or greater than now, but I can't seem to get this figured out. Anyone have any suggestions? Below is my code.
<?php // load records from 'event_signups'
list($event_signupsRecords, $event_signupsMetaData) = getRecords(array(
'tableName' => 'event_signups',
'loadUploads' => true,
'where' => "registrant_user_number = '". $CURRENT_USER['num'] ."' AND reminder_sent = '0'",
//'where' => 'Date > NOW()', // shows only events that have not expired
'allowSearch' => false,
));
?>
<?php foreach ($event_signupsRecords as $record): ?>
<?php /*?><?php if ($record['event_date'] = 'Date > NOW()'): ?><?php */?>
<?php //Get the current time and date in SQL format
$currentDate = date('D, M jS, Y g:i:s a');
if ($record['event_date'] >= '$currentDate'): ?>
<div>
<h6><?php echo $record['event_name:label'] ?></h6>
<div><?php echo date("D, M jS, Y g:i:s a", strtotime($record['event_date'])) ?></div>
<?php if ($record['event_summary']): ?>
<div><?php echo htmlencode($record['event_summary']) ?></div>
<?php endif ?>
</div>
<?php endif ?>
<?php endforeach ?>
By Dave - June 17, 2015
Hi Zicky,
Are you just wanting to show events that "have a date equal to or greater than now"? Or are you wanting to show those AND other events. Because if it's the first one you can just do the query in your MySQL Where and you don't need to put anything extra in your PHP code to compare dates. Try this:
'where' => "registrant_user_number = '". mysql_escape($CURRENT_USER['num']) ."' AND reminder_sent = '0' AND `event_date` >= TIMESTAMP(CURDATE(), '00:00:00')",
Note that I used "TIMESTAMP(CURDATE(), '00:00:00')" instead of NOW() so events without a time specified will always show for the current day (even if you're at 11:00am in the current day and the event has a start time of 00:00:00, which would put the event technically "before" the current time).
Let me know if that works for you.
interactivetools.com
By Mikey - June 17, 2015 - edited: June 17, 2015
Correct - events equal to or greater than todays date, including the requirements of the line of code below.
'where' => "registrant_user_number = '". mysql_escape($CURRENT_USER['num']) ."' AND reminder_sent = '0' AND `event_date` >= TIMESTAMP(CURDATE(), '00:00:00')",
Works like a charm! Thanks Dave!