count record based on variable

Asked

Viewed 67 times

1

Hello

I am trying to build a search in the Mysql record by two parameters; name and dates.

For example, I need to do an execution in Php where I enter the name of who registered ( Box) and dates that occurred the registration( From date x to date y). So far I have obtained this line of code that informs me in an organized way everything that has in the table. But in my search I did not find any native mysql command that filters the way I need.

Can someone tell me what I should do to separate and display only the data I need? Thanks a lot.

<?php
 $caixa= $_POST['caixa'];
 $datade=$_POST['datade'];
 #muda o padrão de data é indespensavel para o mysql ler os dados
 $datade= date("Y-m-d",strtotime(str_replace('/','-',$datade)));
 $dataate=$_POST['dataate'];
 #muda o padrão de data é indespensavel para o mysql ler os dados
 $dataate= date("Y-m-d",strtotime(str_replace('/','-',$dataate)));

 $sql= mysqli_query($conn,"SELECT caixa,data COUNT(*) FROM clientes group by caixa");

 echo "$sql";
 ?>
  • "SELECT caixa, data COUNT(*) FROM clientes where data >=".$datade." and data <=".$dataate." group by caixa" this if you want to include records made also on the two reference dates. If you want only between them, remove the = of comparison.

1 answer

1


Use Mysql’s BETWEEN to search for a range.

$sql= mysqli_query($conn,"SELECT caixa, data, COUNT(*) FROM clientes WHERE caixa = '{$caixa}' AND data BETWEEN '{$datade}' AND '{$dataate}' GROUP BY caixa, data"); 

Browser other questions tagged

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