count register based on variable

1

Hello

I'm trying to build a mysql registry search by two parameters; name and dates.

For example, I need to do a Php run where I give the name of who registered (Box) and dates that the registration occurred (From data x to date y).  So far I've got this line of code that tells me in an organized way everything you have on the table. But in my search I did not find any native mysql command that filters the way I need it.

Can anyone tell me what to do to separate and display only the data I need? Thank you in advance.

<?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";
 ?>
    
asked by anonymous 09.05.2016 / 19:41

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"); 
    
25.05.2016 / 11:16