See table by date

Asked

Viewed 39 times

0

Guys, I have a table that the data is recorded as follows:

ID CANAL VALOR DATA
25 10    50    2016-10-14 14:10:05
26 11    12    2016-10-14 14:10:06
27 10    51    2016-10-14 15:10:10

Both records are recorded hourly, so I need to consult them and show them one by one per channel.

I’m doing it this way:

$contador = 0;
while($contador <= 24){

  if($contador == 0){
    $horario[$contador] = '00:00';
  } else {
    $horario[$contador] = '0'.$contador.':00';
  }

  $data = "2016-10-14";

  $query = $pdo->query("SELECT * FROM valores_d WHERE data_hora BETWEEN ('2016-13 12:00:00') AND ('2016-10-15 13:00:00') order by id desc limit 1");
  $resultado = $query->fetch(PDO::FETCH_ASSOC);

  $arr[$contador] = $resultado['valor'];

  $contador++;

}
  • what would be the doubt?

  • Need to bring the records as follows: Value: 30 Time: 15:10:10 Value: 35 Time: 16:10:10

  • specify, you want to return the records according to date, type, the earliest records first, or the oldest, or the first ones are the ones that you most value?

  • I need the last 24 hour records, for example, time record 00:00, 01:00 to 23:00

  • The question seems easy, but got confused what you really want. I believe that all this can be solved using only SQL.

  • because it does not make the colunda DATE and TIME to specify the date in the search time?

Show 1 more comment
No answers

Browser other questions tagged

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