0
I would like to list the data filtering by the form fields and if nothing is sent, I would like to not display results.
php.
<div class="row container">
<div class="col s12">
<h5 class="light">Gravações</h5><hr>
<form action="BD/read-gravacoes.php" method="post" class="col s12">
<fieldset class="formulario" style="padding: 15px">
<!-- CAMPO NOME -->
<div class="input-field col s12">
<i class="material-icons prefix">phone</i>
<input type="text" name="telefone" id="telefone" maxlength="40" autofocus>
<label for="telefone">Telefone</label>
</div>
<!-- BOTÕES -->
<div class="input-field col s12">
<input type="submit" value="Pesquisar" class="btn blue">
<input type="reset" value="limpar" class="btn red">
</div>
</fieldset>
</form>
<table class="striped">
<thead>
<tr>
<th>Nome</th>
<th>Email</th>
<th>Telefone</th>
</tr>
</thead>
<tbody>
<?php
include_once 'BD/read-gravacoes.php';
?>
</tbody>
</table>
</div>
</div>
read-write.php
<?php
include_once 'conexao.php';
$telefone = filter_input(INPUT_POST, 'telefone', FILTER_SANITIZE_SPECIAL_CHARS);
$inicio = filter_input(INPUT_POST, 'inicio', FILTER_SANITIZE_SPECIAL_CHARS);
$fim = filter_input(INPUT_POST, 'fim', FILTER_SANITIZE_SPECIAL_CHARS);
$querySelect = $link->query("select * from tb_gravacoes");
if(isset($telefone)){
$querySelect .= " WHERE telefone = $telefone";
}
elseif(isset($inicio)){
$querySelect .= " WHERE data >= $inicio AND data <= $fim";
}
else {
$querySelect .= " WHERE id = 0";
}
while($registros = $querySelect->fetch_assoc()):
$id = $registros['id'];
$fila = $registros['fila'];
$telefone = $registros['telefone'];
$gravacao = $registros['gravacao'];
echo "<tr>";
echo "
<td>$fila</td>
<td>$telefone</td>
<td>$gravacao</td>
";
echo "</tr>";
endwhile;
When I click on search, I get the return of the second image.