I'm creating a filter for a database search in a PHP application and obviously I have a lot of criteria, but I've only managed to work with only one criterion.
Code:
select codigo, despesa, data, estabelecimento, valor from financeiro where codigo = 603;
So it obviously works perfectly.
However, on a page I need to leave some criteria blank, as in the example.
On the assumption that the user left the establishment field empty, however, it does not return any value, when it should show the same as the first query.
<?php
include "conexao_bd.inc";
$codigo = $_POST["codigo"];
$data = $_POST["data"];
$hora = $_POST["hora"];
$despesa = $_POST["despesa"];
$valor = $_POST["valor"];
$modo = $_POST["modo"];
$observacao = $_POST["observacao"];
$estabelecimento = $_POST["estabelecimento"];
$genero = $_POST["genero"];
$tipo = $_POST["tipo"];
$resultado = mysqli_query($link, "select * from financeiro where codigo like '$codigo' and data like '$data' and hora like '$hora' and despesa like '$despesa' and valor like '$valor' and modo like '$modo' and observacao like '$observacao' and estabelecimento like '$estabelecimento' and genero like '$genero' and tipo = '$tipo'");
//Escrevendo a tabela.
echo "<table border=1>";
echo "<tr><td><strong>Código</strong></td><td><strong>Data</strong></td><td><strong>Hora</strong></td><td><strong>Despesa</strong></td><td><strong>Valor</strong></td><td><strong>Modo</strong></td><td><strong>Observação</strong></td><td><strong>Estabelecimento</strong></td><td><strong>Gênero</strong></td><td><strong>Tipo</strong></td></tr>";
while($linha = mysqli_fetch_assoc($resultado)) {
echo "<tr>
<td>".$linha['codigo']."</td>
<td>".$linha['data']."</td>
<td>".$linha['hora']."</td>
<td>".$linha['despesa']."</td>
<td>".$linha['valor']."</td>
<td>".$linha['modo']."</td>
<td>".$linha['observacao']."</td>
<td>".$linha['estabelecimento']."</td>
<td>".$linha['genero']."</td>
<td>".$linha['tipo']."</td>
</tr>";
}
echo "</table>";
? >
Could someone give me a light? Thankful.