Select prioritized and ordered by field

Asked

Viewed 65 times

0

BASE DE DADOS

Well I have a schedule schedule table and I need to display the announcer who is live at the moment, I’m picking up via php the dates and playing in select but several times leaves or disorderly or does not leave for sure I will try to summarize what I have to facilitate. Remembering that you can have the same schedule on different days, so ORDER BY FIELD will give priority to $today.

 <?php
 $diasemana = array('Domingo', 'Segunda', 'Terca', 'Quarta', 'Quinta', 'Sexta', 'Sabado');
 $data = date('Y-m-d');
 $diasemana_numero = date('w', strtotime($data));
 $hoje = $diasemana[$diasemana_numero];

 $hora = date("H");
 $minuto = date("i");
 $horaatual = $hora."h".$minuto;
 try {
    $sql = "SELECT * FROM programacao WHERE horafinal >= '$horaatual' ORDER BY FIELD(dias,'$hoje','De Segunda a Sexta','De Segunda a Sabado'), horafinal ASC LIMIT 1";

I don’t know if this in logic or programming even the error, if anyone has any better idea also accept suggestions.

  • Please avoid using high box in the question title unless it is really necessary (for acronyms, etc).

  • What is the "type" of these initial and final columns ? Being numerical you could use a current-time BETWEEN to know what is (or should) in the air. https://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#operator_between http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_current-time

  • This in vachar the fields I could change to datetime more I would like to know how to sort even being text.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.