Filter table php mysql by date

2

I have a table in a php page that displays the clients who have submitted leads to the site. How can I create an input where the user places a date and only shows the leads sent on this date?

<?php
header('Content-Type: text/html; charset=utf-8');

$host = "localhost";
$usuario = "";
$senha = "";
$bd = "";

$mysqli = new mysqli($host,$usuario,$senha, $bd);  /*Conecta no bando de dados MySql*/

$consulta_carro = "SELECT * FROM automovel";
$consulta_moto = "SELECT * FROM moto";
$consulta_casa = "SELECT * FROM casa";

$con_carro = $mysqli->query($consulta_carro) or die ($conexao->error);
$con_moto = $mysqli->query($consulta_moto) or die ($conexao->error);
$con_casa = $mysqli->query($consulta_casa) or die ($conexao->error);

$datahora = "d/m/Y - H:i:s";

?>


<html>
 <head>

 </head>
 <body>
    <div class="center">
    <h2>Automóvel</h2>
    <table class="tabela">
        <tr>
            <!--<td>Valor</td>-->
            <td class="linha-nome">Nome</td>
            <td class="linha-cidade">Cidade</td>
            <td class="linha-telefone">Telefone</td>
            <td class="linha-email">Email</td>
            <td>Data de envio</td>
        </tr>
        <?php while($dado = $con_carro->fetch_array()){ ?>
        <tr>            
            <!--<td><?php // echo $dado['valor'] ?></td>-->
            <td class="capitalize"><?php echo $dado["nome"] ?></td>
            <td class="capitalize"><?php echo $dado["cidade"] ?></td>
            <td class="capitalize"><?php echo $dado["telefone"] ?></td>
            <td class="capitalize"><?php echo $dado["email"] ?></td>
            <td class="capitalize"><?php echo date($datahora, strtotime($dado['data_cadastro'])) ?></td>
        </tr>
        <?php } ?>
    </table>    
    </div>
 </body>
</html

If you want to see the tables, you are in this page

    
asked by anonymous 31.10.2016 / 18:35

1 answer

2

What you need, would be something similar to this, I believe:

$dataInput = '31/10/2016 10:20:00'; //equivalente -> $dataInput = $_POST['data_automovel'];

//ou somente a data
$dataInput = '31/10/2016'; //equivalente -> $dataInput = $_POST['data_automovel'];

 //ou somente dia, mes e horário...
$dataInput = '31/10 10:20:00'; //equivalente -> $dataInput = $_POST['data_automovel'];

//entre outros likes...

$consulta_carro = "SELECT * FROM automovel
where DATE_FORMAT(data_envio, '%d/%m/%Y %H:%i:%s') LIKE '%$dataInput%'"; 

Or more precisely just by date:

$dataInput = '31/10/2016'; //equivalente -> $dataInput = $_POST['data_automovel'];

$consulta_carro = "SELECT * FROM automovel
where DATE_FORMAT(data_envio, '%d/%m/%Y') = '$dataInput'"; 
    
31.10.2016 / 19:27