I have the following table containing the programming of the day of the week "Sunday" of a radio:
(id, program, description, time_ini, end_time, link)
I want to get the first 3 programs using the current time as a reference.
I have the following table containing the programming of the day of the week "Sunday" of a radio:
(id, program, description, time_ini, end_time, link)
I want to get the first 3 programs using the current time as a reference.
Evaluate if the following code will serve you.
-- código #1
SELECT id, programa, descricao, hora_ini, hora_fim, link
from tbProgramacao
where id >= (SELECT id
from tbProgramacao
where hora_ini <= curtime()
order by hora_ini desc
limit 1)
order by hora_ini asc
limit 3;
To get the schedule that is on the air, you can walk in the table in the reverse order (from last to first), comparing with the current time. Once the programming id is in progress, just get the 3
I have not programmed for MySQL for some time; please test the code carefully.
In the WHERE clause of the main SELECT (the external), instead of id you can use time_ini:
where hora_ini >= (SELECT hora_ini