CharlesCorreaWS

Auto complete php

May 17th, 2020
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.32 KB | None | 0 0
  1. <!--- auto complete html --->
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5.     <title>Autocomplete</title>
  6.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  7.     <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.min.js"></script>
  8.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  9. </head>
  10. <body>
  11. <br /><br />
  12. <div class="container" style="width:600px;">
  13.     <label>Pessoa</label>
  14.     <input type="text" name="Pessoa" id="Campo_Pesquisa" class="form-control input-lg" autocomplete="off" placeholder="Digite o nome da pessoa" />
  15.     <label>Id</label>
  16.     <input type="text" name="Id" id="Id_Pessoa" class="form-control input-lg" autocomplete="off" placeholder="Id da pessoa" />
  17.  
  18. </div>
  19.  
  20. <script>
  21.     $(document).ready(function(){
  22.         $('#Campo_Pesquisa').typeahead({
  23.             source: function(query, result)
  24.             {
  25.                 $.ajax({
  26.                     url:"BuscaPessoa.php",
  27.                     method:"POST",
  28.                     data:{query:query},
  29.                     dataType:"json",
  30.                     success:function(data)
  31.                     {
  32.                         result($.map(data, function(item){
  33.                             return item;
  34.                         }));
  35.                     }
  36.                 })
  37.             }
  38.         });
  39.  
  40.     });
  41. </script>
  42. </body>
  43. </html>
  44.  
  45. <!--- auto complete html --->
  46.  
  47. <!--- auto complete php consulta BuscaPessoa.php --->
  48.  
  49. <?php
  50. header('Content-Type: application/json; charset=utf-8');
  51. require "../../Includes/Config/ConfigSystem.php";
  52. require "../../Includes/Functions/Seguranca.php";
  53. require "../../Includes/Databases/MySQL_Default_System.php";
  54.  
  55. $SQL_Busca = "
  56. SELECT SQL_CACHE Nome_Religioso, ID_Pessoa
  57. FROM pessoas
  58. WHERE Nome_Religioso
  59. LIKE '%$PalavraPraBusca%'
  60. ";
  61.  
  62.  
  63. $Busca = $ConnectionSystem->query($SQL_Busca) or die($ConnectionSystem->error);
  64. $DadosAutoComplete = array();
  65.  
  66. if ($Busca->num_rows > 0) {
  67.     while($Dados = $Busca->fetch_assoc()) {
  68.         $DadosAutoComplete[]= $Dados['Nome_Religioso'];
  69.  
  70.     }
  71.     echo json_encode($DadosAutoComplete,JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
  72. }
  73.  
  74. $ConnectionSystem->close();
  75.  
  76. ?>
  77.  
  78. <!--- auto complete php consulta BuscaPessoa.php --->
Add Comment
Please, Sign In to add comment