1
I’m having problems to make a search system, at the moment I do the search/comparison with 2 columns and shows the name of the 2 columns.
  $pesquisa = filter_input(INPUT_GET, 'term', FILTER_SANITIZE_STRING);
  $result_pesquisa = "SELECT Ativo, Empresa FROM tb_ativos WHERE Ativo LIKE '%{$pesquisa}%' OR Empresa LIKE '%{$pesquisa}%' ORDER BY Ativo ASC LIMIT 10";
  $resultado_final = $conn->prepare($result_pesquisa);
  $resultado_final->execute();
  while($row_pesquisa = $resultado_final->fetch(PDO::FETCH_ASSOC)){
    $data[] = $row_pesquisa['Ativo'] . " - " . $row_pesquisa['Empresa'];
  }
  echo json_encode($data);
On the main page is this excerpt
<script type="text/javascript">
      $(function(){
        $("#ativo").autocomplete({
          source: 'pesquisa-ativo.php'
        });
      });
    </script>
And returns me what I want, no matter if the user writes the corresponding name of the first or second column, will appear to msm thing for both
On the main page has a code similar to the first mentioned, but showing the id tbm as a result, if I try to write any name q is in the 2 columns and give Enter it will return me to msm thing, so far so good
The problem is when I click on one of the search suggestions and perform the search, as n exists in no column the junction of the two names, it n returns the search
I would like to know how to get only the first word when selected one of the suggested options of the autocomplete, I believe I can deal with jquery in this code snippet, but I’m not able to do
    <script type="text/javascript">
      $(function(){
        $("#ativo").autocomplete({
          source: 'pesquisa-ativo.php'
        });
      });
    </script>


