Find other select results

Asked

Viewed 45 times

-1

Good morning guys!

I have a code where I search the registers around the city. Code below:

<form name="frmBusca" method="post" class="w3-container w3-center w3-row-padding" action="<?php echo htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES, "UTF-8"); ?>?a=buscar">

<div class="w3-section"><h4 class="w3-text-black">Nome:</h4><input type="texto" class="" name="nome" placeholder="Nome"/></div>
<div class="w3-section"><h4 class="w3-text-black">Função:</h4><input type="texto" name="cargo_pretendido"  placeholder="Ex: Motorista"/></div>
<div class="w3-section"><h4 class="w3-text-black">Cidade:</h4>
        <select type="checkbox" class="w3-center w3-bordered" style="width:207px;" name="cidade">
                <option value="%%%%">TODOS</option>
                <option value="camboriu">Camboriú</option>
                <option value="balneario camboriu">Balneário Camboriú</option>
                <option value="itapema">Itapema</option>
                <option value="porto">Porto Belo</option>
                <option value="itajai">Itajaí</option>
        </select></div>    




PHP

 <?php

if ($a == "buscar") {

$id = trim($_POST['id']);
$nome = trim($_POST['nome']);
$endereco = trim($_POST['endereco']);
$numero = trim($_POST['numero']);
$cidade = trim($_POST['cidade']);
$bairro = trim($_POST['bairro']);
$telefone = trim($_POST['telefone']);
$celular = trim($_POST['celular']);
$email = trim($_POST['email']);
$data_nascimento = trim($_POST['data_nascimento']);
$estado_civil = trim($_POST['estado_civil']);
$habilitado = trim($_POST['habilitado']);
$n_registro = trim($_POST['n_registro']);
$categoria = trim($_POST['categoria']);
$cpf = trim($_POST['cpf']);
$rg = trim($_POST['rg']);
$cargo_pretendido = trim($_POST['cargo_pretendido']);
$nivel_hierarquico = trim($_POST['nivel_hierarquico']);
$area_atuacao = trim($_POST['area_atuacao']);
$grau_instrucao = trim($_POST['grau_instrucao']);
$tecnico_data = trim($_POST['tecnico_data']);
$superior_data = trim($_POST['superior_data']);
$empresa1 = trim($_POST['empresa1']);
$cargoempresa1 = trim($_POST['cargoempresa1']);
$dt_admissao1 = trim($_POST['dt_admissao1']);
$dt_demissao1 = trim($_POST['dt_demissao1']);
$empresa2 = trim($_POST['empresa2']);
$cargoempresa2 = trim($_POST['cargoempresa2']);
$dt_admissao2 = trim($_POST['dt_admissao2']);
$dt_demissao2 = trim($_POST['dt_demissao2']);
$empresa3 = trim($_POST['empresa3']);
$cargoempresa3 = trim($_POST['cargoempresa3']);
$dt_admissao3 = trim($_POST['dt_admissao3']);
$dt_demissao3 = trim($_POST['dt_demissao3']);
$observacoes = trim($_POST['observacoes']);

    $sql = "SELECT * FROM pr_curriculo WHERE id LIKE '%".$id."%' AND nome LIKE '%".$nome."%' AND endereco LIKE '%".$endereco."%' AND numero LIKE '%".$numero."%' AND cidade LIKE '".$cidade."%' AND bairro LIKE '%".$bairro."%' AND telefone LIKE '%".$telefone."%' AND celular LIKE '%".$celular."%' AND email LIKE '%".$email."%' AND data_nascimento LIKE '%".$data_nascimento."%' AND estado_civil LIKE '%".$estado_civil."%' AND habilitado LIKE '%".$habilitado."%' AND n_registro LIKE '%".$n_registro."%' AND categoria LIKE '%".$categoria."%' AND cpf LIKE '%".$cpf."%' AND rg LIKE '%".$rg."%' AND cargo_pretendido LIKE '%".$cargo_pretendido."%' AND nivel_hierarquico LIKE '%".$nivel_hierarquico."%' AND area_atuacao LIKE '%".$area_atuacao."%' AND grau_instrucao LIKE '%".$grau_instrucao."%' AND tecnico_data LIKE '%".$tecnico_data."%' AND superior_data LIKE '%".$superior_data."%' AND empresa1 LIKE '%".$empresa1."%' AND cargoempresa1 LIKE '%".$cargoempresa1."%' AND dt_admissao1 LIKE '%".$dt_admissao1."%' AND dt_demissao1 LIKE '%".$dt_demissao1."%' AND empresa2 LIKE '%".$empresa2."%' AND cargoempresa2 LIKE '%".$cargoempresa2."%' AND dt_admissao2 LIKE '%".$dt_admissao2."%' AND dt_demissao2 LIKE '%".$dt_demissao2."%' AND empresa3 LIKE '%".$empresa3."%' AND cargoempresa3 LIKE '%".$cargoempresa3."%' AND dt_admissao3 LIKE '%".$dt_admissao3."%' AND dt_demissao3 LIKE '%".$dt_demissao3."%' AND curso LIKE '%".$curso."%' AND observacoes LIKE '%".$observacoes."%'";

    $query = mysqli_query($conexao, $sql); 
    $qt_linhas= mysqli_num_rows($query);

    ?>

I want to have an option that searches all results except the above, how can I do that? Remembering that the other results are several cities, not only two or three...

  • Post the javascript you are requesting for the back-end. But this is not to limit direct on SELECT of the bank using a NOT IN, for example ?

  • I have a $sql that searches all the information in the bank. When it was the other option I would have to have a $sql2 that looked for everything except those cities above?

  • My sql looks like this... $sql = "SELECT * FROM pr_curriculo WHERE id LIKE '%". $id." %' AND name LIKE '%". $name." %' AND address LIKE '%". $address." %' AND numero LIKE '%". $numero." %' AND cidade LIKE '". $cidade."%'

  • As you want to pursue various values, I recommend using the IN instead of like.

  • I don’t understand... I want to search one value at a time. A query "beautiful port", a query "Tapema", a query "other"..

  • Right, so in the option "other" will not look for the options listed? "Camboriu", "Itapema", etc? Are only these options?

  • That, others search everything except those already cited.

  • Right. Post your file PHP that receives this data for me to create an example.

  • http://dontpad.com/phpstackoverflow Here’s the code, it’s kind of big. If you need any other part of the code just ask...

Show 4 more comments

1 answer

1


First, you will need to identify which valor is being captured in the variable $cidade to then take action.

The logic is quite simple: If the value is equal to OUTROS, the select will be mounted denying the cities you do not want to bring, if the value is different from OUTROS, will search for the city that is posted.

Your code will look like this:

  <?php

if ($a == "buscar") {

$id = trim($_POST['id']);
$nome = trim($_POST['nome']);
$endereco = trim($_POST['endereco']);
$numero = trim($_POST['numero']);
$cidade = trim($_POST['cidade']);
$bairro = trim($_POST['bairro']);
$telefone = trim($_POST['telefone']);
$celular = trim($_POST['celular']);
$email = trim($_POST['email']);
$data_nascimento = trim($_POST['data_nascimento']);
$estado_civil = trim($_POST['estado_civil']);
$habilitado = trim($_POST['habilitado']);
$n_registro = trim($_POST['n_registro']);
$categoria = trim($_POST['categoria']);
$cpf = trim($_POST['cpf']);
$rg = trim($_POST['rg']);
$cargo_pretendido = trim($_POST['cargo_pretendido']);
$nivel_hierarquico = trim($_POST['nivel_hierarquico']);
$area_atuacao = trim($_POST['area_atuacao']);
$grau_instrucao = trim($_POST['grau_instrucao']);
$tecnico_data = trim($_POST['tecnico_data']);
$superior_data = trim($_POST['superior_data']);
$empresa1 = trim($_POST['empresa1']);
$cargoempresa1 = trim($_POST['cargoempresa1']);
$dt_admissao1 = trim($_POST['dt_admissao1']);
$dt_demissao1 = trim($_POST['dt_demissao1']);
$empresa2 = trim($_POST['empresa2']);
$cargoempresa2 = trim($_POST['cargoempresa2']);
$dt_admissao2 = trim($_POST['dt_admissao2']);
$dt_demissao2 = trim($_POST['dt_demissao2']);
$empresa3 = trim($_POST['empresa3']);
$cargoempresa3 = trim($_POST['cargoempresa3']);
$dt_admissao3 = trim($_POST['dt_admissao3']);
$dt_demissao3 = trim($_POST['dt_demissao3']);
$observacoes = trim($_POST['observacoes']);

if($cidade == "OUTROS") {
    $sql = "SELECT * FROM pr_curriculo WHERE id LIKE '%".$id."%' AND nome LIKE '%".$nome."%' AND endereco LIKE '%".$endereco."%' AND numero LIKE '%".$numero."%' AND cidade NOT IN ('cidade1', 'cidade2', 'cidade3' etc...) AND bairro LIKE '%".$bairro."%' AND telefone LIKE '%".$telefone."%' AND celular LIKE '%".$celular."%' AND email LIKE '%".$email."%' AND data_nascimento LIKE '%".$data_nascimento."%' AND estado_civil LIKE '%".$estado_civil."%' AND habilitado LIKE '%".$habilitado."%' AND n_registro LIKE '%".$n_registro."%' AND categoria LIKE '%".$categoria."%' AND cpf LIKE '%".$cpf."%' AND rg LIKE '%".$rg."%' AND cargo_pretendido LIKE '%".$cargo_pretendido."%' AND nivel_hierarquico LIKE '%".$nivel_hierarquico."%' AND area_atuacao LIKE '%".$area_atuacao."%' AND grau_instrucao LIKE '%".$grau_instrucao."%' AND tecnico_data LIKE '%".$tecnico_data."%' AND superior_data LIKE '%".$superior_data."%' AND empresa1 LIKE '%".$empresa1."%' AND cargoempresa1 LIKE '%".$cargoempresa1."%' AND dt_admissao1 LIKE '%".$dt_admissao1."%' AND dt_demissao1 LIKE '%".$dt_demissao1."%' AND empresa2 LIKE '%".$empresa2."%' AND cargoempresa2 LIKE '%".$cargoempresa2."%' AND dt_admissao2 LIKE '%".$dt_admissao2."%' AND dt_demissao2 LIKE '%".$dt_demissao2."%' AND empresa3 LIKE '%".$empresa3."%' AND cargoempresa3 LIKE '%".$cargoempresa3."%' AND dt_admissao3 LIKE '%".$dt_admissao3."%' AND dt_demissao3 LIKE '%".$dt_demissao3."%' AND curso LIKE '%".$curso."%' AND observacoes LIKE '%".$observacoes."%'";
}

else {
    $sql = "SELECT * FROM pr_curriculo WHERE id LIKE '%".$id."%' AND nome LIKE '%".$nome."%' AND endereco LIKE '%".$endereco."%' AND numero LIKE '%".$numero."%' AND cidade LIKE '".$cidade."%' AND bairro LIKE '%".$bairro."%' AND telefone LIKE '%".$telefone."%' AND celular LIKE '%".$celular."%' AND email LIKE '%".$email."%' AND data_nascimento LIKE '%".$data_nascimento."%' AND estado_civil LIKE '%".$estado_civil."%' AND habilitado LIKE '%".$habilitado."%' AND n_registro LIKE '%".$n_registro."%' AND categoria LIKE '%".$categoria."%' AND cpf LIKE '%".$cpf."%' AND rg LIKE '%".$rg."%' AND cargo_pretendido LIKE '%".$cargo_pretendido."%' AND nivel_hierarquico LIKE '%".$nivel_hierarquico."%' AND area_atuacao LIKE '%".$area_atuacao."%' AND grau_instrucao LIKE '%".$grau_instrucao."%' AND tecnico_data LIKE '%".$tecnico_data."%' AND superior_data LIKE '%".$superior_data."%' AND empresa1 LIKE '%".$empresa1."%' AND cargoempresa1 LIKE '%".$cargoempresa1."%' AND dt_admissao1 LIKE '%".$dt_admissao1."%' AND dt_demissao1 LIKE '%".$dt_demissao1."%' AND empresa2 LIKE '%".$empresa2."%' AND cargoempresa2 LIKE '%".$cargoempresa2."%' AND dt_admissao2 LIKE '%".$dt_admissao2."%' AND dt_demissao2 LIKE '%".$dt_demissao2."%' AND empresa3 LIKE '%".$empresa3."%' AND cargoempresa3 LIKE '%".$cargoempresa3."%' AND dt_admissao3 LIKE '%".$dt_admissao3."%' AND dt_demissao3 LIKE '%".$dt_demissao3."%' AND curso LIKE '%".$curso."%' AND observacoes LIKE '%".$observacoes."%'";
}

    $query = mysqli_query($conexao, $sql); 
    $qt_linhas= mysqli_num_rows($query);

    ?>

Remarks:

On your form:

<

form name="frmBusca" method="post" class="w3-container w3-center w3-row-padding" action="<?php echo htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES, "UTF-8"); ?>?a=buscar">

<div class="w3-section"><h4 class="w3-text-black">Nome:</h4><input type="texto" class="" name="nome" placeholder="Nome"/></div>
<div class="w3-section"><h4 class="w3-text-black">Função:</h4><input type="texto" name="cargo_pretendido"  placeholder="Ex: Motorista"/></div>
<div class="w3-section"><h4 class="w3-text-black">Cidade:</h4>
        <select type="checkbox" class="w3-center w3-bordered" style="width:207px;" name="cidade">
                <option value="OUTROS">TODOS</option>
                <option value="camboriu">Camboriú</option>
                <option value="balneario camboriu">Balneário Camboriú</option>
                <option value="itapema">Itapema</option>
                <option value="porto">Porto Belo</option>
                <option value="itajai">Itajaí</option>
        </select></div> 

In PHP code, remember to put cities that will not be included in select within if.

  • Solved my problem! I just had a few obstacles with people writing "Tajai sc" instead of Tajaí, but nothing that we can’t get around. Thank you for your resolution!

  • @Mickaelrocha how nice to be able to help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.