1
I’m having doubts in extracting data from the last hour of the mysql database, the code below makes the sum of values in the table for the last day, more relating for the last hour I’m not able to do.
$busca = mysql_connect("$local","$usuario","$senha") or die("ERRO AO CONECTAR AO MYSQL, VERIFIQUE COM O ADMINISTRADOR" . mysql_error());
mysql_select_db("$banco") or die("BASE DE DADOS INVÁLIDO");
$pesquisa = mysql_query("SELECT sum(ProdValor) FROM vendas WHERE data BETWEEN CURRENT_DATE()-30 AND CURRENT_DATE()");
while($sum = mysql_fetch_array($pesquisa)){
$soma5 = $sum['sum(ProdValor)'];
}
//Mostrando o Resultado
//$resultado = number_format($soma,2,",",".");
echo $soma5;
What is the format of the field
data
?– Sergio
@Sergio is in date format.
– the flash
Experiment with
WHERE data >= DATE_SUB(NOW(), INTERVAL 1 HOUR)
– Sergio
@Sergio updated to:
mysql_query("SELECT sum(ProdValor) FROM vendas WHERE data >= DATE_SUB(NOW(), INTERVAL 1 HOUR)");
and no value is shown, even though there were records in the database 1 hour ago.– the flash