If statement in MySQL query with PHP
Posted
by
user1104854
on Stack Overflow
See other posts from Stack Overflow
or by user1104854
Published on 2012-05-31T22:35:19Z
Indexed on
2012/05/31
22:40 UTC
Read the original article
Hit count: 145
Is it possible to use an if statement in a MySQL query in a similar what I'm showing? I want to grab some information for upcoming events(not ones with previous dates).
ini_set('date.timezone', 'America/New_York');
$timestamp = date('m/d/Y');
$sql = "select eventID,eventTitle,eventDate from events where eventLocationID = $locationID ORDER BY eventDate DESC IF(eventDate > $timestamp) ";
I really want to avoid doing post-query if statements that will only print if it's after today's date because I run it through a pagination function, and I'd really prefer to avoid tinkering with that.
© Stack Overflow or respective owner