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?
– Sampaio Leal
Need to bring the records as follows: Value: 30 Time: 15:10:10 Value: 35 Time: 16:10:10
– Bruno Cesar
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?
– Sampaio Leal
I need the last 24 hour records, for example, time record 00:00, 01:00 to 23:00
– Bruno Cesar
The question seems easy, but got confused what you really want. I believe that all this can be solved using only SQL.
– Inkeliz
because it does not make the colunda DATE and TIME to specify the date in the search time?
– Sampaio Leal