0
I have this code with the 3 selects to filter a query:
<form class="shadowbox6" action="" method="post">
<strong><label for="Estado Encomenda">Estado Encomenda</label></strong>
<select name="pesquisar">
<option></option>
<?php
$sql = "SELECT * FROM centrodb.EstadoEncomendas";
$qr = mysqli_query($conn, $sql);
while($ln = mysqli_fetch_assoc($qr)){
echo '<option value="'.$ln['Estado'].'"> '.$ln['Estado'].'</option>';
}
?>
</select>
<strong><label for="Valência">Valência</label></strong>
<select name="pesquisar">
<option></option>
<?php
$sql = "SELECT * FROM centrodb.Destinos WHERE Id IN (1,2,3)";
$qr = mysqli_query($conn, $sql);
while($ln = mysqli_fetch_assoc($qr)){
echo '<option value="'.$ln['Destino'].'"> '.$ln['Destino'].'</option>';
}
?>
</select>
<strong><label for="Requerente">Requerente</label></strong>
<select name="pesquisar">
<option></option>
<?php
$sql = "SELECT * FROM centrodb.Requerentes WHERE Id IN (1,2,4,5,8)";
$qr = mysqli_query($conn, $sql);
while($ln = mysqli_fetch_assoc($qr)){
echo '<option value="'.$ln['Requerente'].'"> '.$ln['Requerente'].'</option>';
}
?>
</select>
<button class="botao" type="submit">Consultar</button>
</form>
if(isset($_POST['pesquisar']))){
$pesquisar = $_POST['pesquisar'];
$result_cursos = "SELECT IdRequisicao,
CASE WHEN centrodb.EncomendasGerais.Estado IN (1,2,6) THEN DATE(DataEncomenda)
WHEN centrodb.EncomendasGerais.Estado IN (3,4,5,7) THEN DataAprovacao END AS `Data`,
IdTipoProduto,
IdProduto,
Quantidade,
IdRequerente,
IdDestino,
Fornecedor,
centrodb.EstadoEncomendas.Estado,
Preco
FROM centrodb.EncomendasGerais LEFT OUTER JOIN centrodb.EstadoEncomendas
on centrodb.EstadoEncomendas.Id = centrodb.EncomendasGerais.Estado
WHERE centrodb.EstadoEncomendas.Estado LIKE '%$pesquisar%' AND IdDestino LIKE '%$pesquisar%' AND IdRequerente LIKE '%$pesquisar%'
...
}
If using only the first select works well the filter, adding the 3 filter possibilities no longer works.
Put the selects with different Ames, and at the time of the query, see if you received any posts from each select before adding it to the query.
– David Alves