I am building a radio schedule where i want to show the current show or the upcoming or at last the next day's show. If it returns the next day's show i would like to add somthing to the title like CONCAT_WS(" ", "Don't miss tomorrow:", title). The schedule is on JSON format so i am using JSON_EXTRACT and TIME_FORMAT to be able to compare values of hours. Here is what currently works, except that it shows the upcoming show or the next day's. Where there are days like "tuesday" is an example for today and wednesday for tomorrow. The Between condition and the next one, selects current show OR the upcoming for today. How can i check if none of these apply, select the next day's and update the title
SELECT * FROM tableName WHERE visible = 1 AND JSON_UNQUOTE(JSON_EXTRACT(schedule, '$.tuesday.active')) = 1 AND ( ( TIME_FORMAT(NOW(), '%H:%i') BETWEEN TIME_FORMAT(JSON_UNQUOTE(JSON_EXTRACT(schedule, '$.tuesday.time[0]')), '%H:%i') AND TIME_FORMAT(JSON_UNQUOTE(JSON_EXTRACT(schedule, '$.tuesday.time[1]')), '%H:%i') ) OR ( TIME_FORMAT(JSON_UNQUOTE(JSON_EXTRACT(schedule, '$.tuesday.time[0]')), '%H:%i') > TIME_FORMAT(NOW(), '%H:%i') AND TIME_FORMAT(JSON_UNQUOTE(JSON_EXTRACT(schedule, '$.tuesday.time[1]')), '%H:%i') < TIME_FORMAT(NOW(), '%H:%i') ) OR ( id = (SELECT id FROM tableName WHERE visible = 1 AND JSON_UNQUOTE(JSON_EXTRACT(schedule, '$.wednesday.active')) = 1 ORDER BY RAND() LIMIT 1) ) ) LIMIT 1
Aucun commentaire:
Enregistrer un commentaire