0
php collects input data using POST method. It is connected right, is searching, but when typing the UF and Municipality it shows me not only exactly what I typed, but also the related! type typed SP - São Paulo, he does not show me only that it shows SP - São Carlos, SP- São Fulano, SP - São Siclano etc. Anyway, shows all of has s, or ã and I want to show ONLY EXACTLY WHAT I TYPED. If anyone knows and can help I am very grateful. Follow my code:
<?php
include ('conectar.php');
$connection = mysqli_connect($host, $user, $pass,$database);
if (!$connection) { echo ("Erro ao conectar"); }
$opcao = $_POST["opcao"];
if($opcao == "2"){
$sg_uf = '"%'. $_POST["txtsg_uf"] .'%"';
$nm_municipio = '"%'. $_POST["txtnm_municipio"] .'%"';
$nm_candidato = '"%'. $_POST["txtnm_candidato"] .'%"';
$dt_ano = '"%'. $_POST["txtdt_ano"] .'%"';
$query = "SELECT * FROM resultado "
. "WHERE sg_uf LIKE ".$sg_uf." OR nm_municipio LIKE ".$nm_municipio." OR nm_candidato LIKE ".$nm_candidato." OR dt_ano LIKE ".$dt_ano."";
$result = mysqli_query($connection,$query);
if (!$result) {
die("Query inválida na seleção dos dados");
}
while ($dados= mysqli_fetch_array($result,MYSQLI_ASSOC)) {
if ($result > 0){
echo "Opção de Busca Avançada/Eleições Municipais: <br />";
echo "Encontramos!<br/ >";
echo "UF do Estado: $dados[sg_uf]<br />";
echo "Nome do Município: $dados[nm_municipio]<br />";
echo "Nome do Candidato: $dados[nm_candidato]<br />";
echo "Ano da Eleição: $dados[dt_ano]<br />";
echo "<hr>";
}
else {
echo "Desculpe, nada foi encontrado.";
}
}
}
?>
use
AND
if you want results with all conditions.OR
will return you things that have condition A, or condition B, or condition C. Something else,LIKE
is not for exact searches. For exact searches the=
– Bacco
@Bacco I did so but nothing appeared
$query = "SELECT * FROM resultado_votacao_candidato_zona_eleicaomunicipal "
. "WHERE sg_uf = ".$sg_uf." AND nm_municipio = ".$nm_municipio." AND nm_candidato = ".$nm_candidato." AND dt_ano = ".$dt_ano."";
– Sarah