I'm trying to implement a sql query that will retrieve 3 rows closest to the current date. Ideally I would also be pulling an entry with a date greater than or equal to today, however, this isn't always the case. If three entries are not found with current or future dates I need to pull the remaining entries in DESC order from the current date.
A clarification example: I am displaying three calendar events on a homepage and I want there to always be three events. I run a query to get all upcoming events WHERE DATE(date_evnt)>=CURDATE()
ORDER BY date_evnt ASC. If there is only one upcoming event I need to grab two events WHERE DATE(date_evnt)<= CURDATE() ORDER BY date_evnt DESC.
Is it possible that this can be done with a single query or do I have to use a loop?
$query_rs_event = "SELECT * FROM event_evnt WHERE DATE(date_evnt)>=CURDATE() ORDER BY date_evnt ASC LIMIT 3";