I’m trying to setup an automatic event countdown. What I want to do is use MySQL to fill the countdown with the next upcoming event.
If the event is in the future, the code will show ‘upcoming event – countdown’ and if the event is currently taking place then show ‘event happening’.
I have a table structure like this:
CREATE TABLE jos_eventlist_events (
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
catsid INT UNSIGNED,
dates DATE,
times TIME,
enddates DATE,
endtimes TIME,
published TINYINT(1),
title VARCHAR(255)
) Engine=InnoDB;
INSERT INTO jos_eventlist_events
VALUES
(1, 6, '2012-01-15', '21:00', '2012-01-15', '22:00', 1, 'Partying'),
(2, 6, '2012-01-15', '23:00', '2012-01-16', '01:00', 1, 'More partying')
;
So essentially, the query should do something akin to this: If there are no events currently taking place, retrieve the next upcoming event. If there is an event taking place then display it.
The following query is a stepping stone as to what I’m trying to achieve.
SELECT catsid,id,dates,times,endtimes,published,title
FROM jos_eventlist_events
WHERE catsid = 6 AND published = 1
AND dates && times >= CURDATE() && CURTIME()
AND dates && endtimes <= CURDATE() && CURTIME()
LIMIT 1
Keep in mind that my server is 5 hours behind my local time.
I know I’m missing something really silly with this, but any help you can provide will be greatly appreciated.
try (I did not test it):