How to search for users in the database without select option

0

Well, I've always found a bad method that I use to search users in the database in a select option. When I have a lot of records, the page loads and it tends to get worse, does anyone have any idea how I can restructure my search for user by bringing similar users to names and not typing the full name?

clients.php code

<?php
    if (isset($_GET['apagar']) && $_GET['apagar'] == 'excluir') {
        $deleta = mysql_query("DELETE FROM t_cadclientes WHERE Ficha = '$_GET[id]'");
    if($deleta == '1'){
        echo "Cliente deletado com sucesso !";
    echo "<meta HTTP-EQUIV='refresh' CONTENT='2;URL=clientes.php'>";
    }else{
        echo "Erro ao deletar, favor tente novamente !";
}
}
?>
<div id="painelclientes">
<?php
$sql = "SELECT Ficha, Snome FROM t_cadclientes ORDER BY Ficha ASC, Snome ASC";
$resultado = mysql_query($sql)
            or die (mysql_error());
if(@mysql_num_rows($resultado) == 0)
            echo ("Cliente não encontrado(a) !");
?>

<form id="form2" name="form2" method"post" action="" enctype="multipart/form-data">
<div align="center">
  <table border="0" align="center">
      <tr>
        <td><label>
          <select name="id" id="id">
            <option value="-1" selected="selected">Selecione um cliente</option>
            <?php 
    while($linha=mysql_fetch_array($resultado)) {
        $id = $linha[0];
        $Snome = $linha[1];
?>
            <option value="<?php echo $id;?>"><?php echo $Snome;  ?></option>
<?php
    }
?>
          </select>
          </label></td>
          <tr>
        <label>
          <input type="hidden" name="apagar" value="excluir" />
          <input type=image src="../images/excluirOver.png" onMouseOver="this.src='../images/excluir.png'" onMouseOut="this.src='../images/excluirOver.png'" title="Excluir" style="border:0;" name="excluir" id="excluir" value="Excluir" />
          <input type=image src="../images/editarOver.png" onMouseOver="this.src='../images/editar.png'" onMouseOut="this.src='../images/editarOver.png'" title="Editar" style="border:0;" name="Alterar" id="Alterar" value="Alterar" formaction="editar_clientes.php" />
          <input type=image src="../images/vendas_crediarioOver.png" onMouseOver="this.src='../images/vendas_crediario.png'" onMouseOut="this.src='../images/vendas_crediarioOver.png'" title="Venda Crediário" style="border:0;" name="vendas_crediario" id="vendas_crediario" value="vendas_crediario" formaction="vendas_crediario.php" />
          <input type=image src="../images/imprimirOver.png" onMouseOver="this.src='../images/imprimir.png'" onMouseOut="this.src='../images/imprimirOver.png'" title="Imprimir" style="border:0;" name="Imprimir" id="Imprimir" value="Imprimir"  formaction="imprimir_clientes.php" />
          <input type=image src="../images/cadastrarOver.png" onMouseOver="this.src='../images/cadastrar.png'" onMouseOut="this.src='../images/cadastrarOver.png'" title="Cadastrar" style="border:0;" name="cadastrar" id="cadastrar" value="cadastrar"  formaction="cadastro_clientes.php" />
          </label>
      </tr>
</table>
</form>
</div>
    
asked by anonymous 11.10.2014 / 21:55

1 answer

2

You can use this jquery plugin ([ link ) as follows:

Include jQuery and plugin in head:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script><scripttype="text/javascript" src="yourfiles/jquery.tokeninput.js"></script>
<link rel="stylesheet" type="text/css" href="yourfiles/token-input.css" />

and start like this:

<input type="text" name="blah" id="user-input">
<script type="text/javascript">
$(document).ready(function () {
    $("#user-input").tokenInput("/clientes-ajax.php");
});
</script>

the clients-ajax.php file would look something like this to return:

$q = mysql_real_escape_string($_GET['q']);
$resultado = mysql_query("SELECT * FROM users WHERE name LIKE '{$q}%'", $db);  

//Create an array
$json_response = array();
$row_array = array();

while($linha = mysql_fetch_array($resultado)) {
   $row_array['id']= [$linha[0];
   $row_array['name']= [$linha[1];

   //push the values in the array
   array_push($json_response,$row_array);
}
echo json_encode($json_response);
    
12.10.2014 / 15:40