0
I have the following table containing the schedule of the day of the week "Sunday" of a radio:
(id,script,hora_ini,hora_end,link)
I want to get the first 3 programs using as reference the current time.
0
I have the following table containing the schedule of the day of the week "Sunday" of a radio:
(id,script,hora_ini,hora_end,link)
I want to get the first 3 programs using as reference the current time.
2
Evaluate if the following code meets 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 programming that is in the air, you can walk in the table in reverse order (from the last to the first), comparing to the current time. Obtained the id of the programming in progress, just get the 3.
It’s been a while since I’ve programmed for Mysql; please test the code carefully.
In the main SELECT WHERE clause (the external one), in place of id you can use hora_ini:
where hora_ini >= (SELECT hora_ini
Thank you very much. Saved the days.
Browser other questions tagged php mysql sql
You are not signed in. Login or sign up in order to post.
You are using the column with the type
TIME
?– Inkeliz
@Atilacardoso: What is the database manager? // How are the hora_ini and hora_fim columns declared? // You want an SQL query or treat directly in PHP code?
– José Diz
Yes. I use the time column; The manager is mysql. I prefer a query but if it is not possible the processing with php will be an output as well
– Atila Silva
Welcome to read this post https://pt.meta.stackoverflow.com/questions/5483/manual-de-como-n%C3%83o-fazer-perguntas/5485#5485
– user60252
Thanks Leo Caracciolo. Next time I will follow the recommendations.
– Atila Silva