I have a list of events, which are either single day events or multiple day events. If they are a single day they simply have a startDate field. If they are a multiple day event they have a startDate and an endDate.
What I want is just to show the next seven days events, but split the events into each day. So, there would be a header for Monday and then a list of Monday’s events, and so on. If the event lasted all week it would show under each day.
Okay, now I have this short piece of code that works out the next seven days and their headers. How would I begin to incoporate the events into this loop? Any help would be massively appreciated!
please try this query and let me know how it works
it’s a single query that returns all events in the next 7 days (including today)
note that you will be looping over the query results to print the events, rather than looping to query them
SELECT d.eventdate
, e.eventname
FROM ( SELECT CURRENT_DATE + INTERVAL numbers.n DAY AS eventdate
FROM ( SELECT 0 AS n
UNION ALL
SELECT 1
UNION ALL
SELECT 2
UNION ALL
SELECT 3
UNION ALL
SELECT 4
UNION ALL
SELECT 5
UNION ALL
SELECT 6 ) AS numbers
) AS d
LEFT OUTER
JOIN events AS e
ON d.eventdate BETWEEN e.startDate
AND COALESCE(e.startDate,e.endDate)
ORDER
BY d.eventdate