I have a table that data is written 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 look at 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++;
}