是否可以在 MySQL 查询中使用类似于我所展示的 if 语句?我想获取一些即将发生的事件的信息(不是以前日期的事件)。
ini_set('date.timezone', 'America/New_York');
echo $timestamp = date('Y-m-d');
$sql = "select eventID,eventTitle,eventDate from events where eventLocationID = $locationID AND (eventDate > $timestamp) ORDER BY eventDate ASC";
编辑 - sql 语句没有过滤掉今天之前的日期(它正在显示所有内容)。
例如,我回显时间戳只是为了确保它设置正确。在我的表格中,我输入了两个日期,一个在 1 月,一个在今天。
所以这是输出
2012-05-31 //timestamp, not part of results. just for reference
2012-01-10 //first result, however it shouldn't display
2012-06-22 //this should be the only result that displays