0
Good staff always found bad a method I use to search users in the database in a select option, when I have many records the page takes to load and only tends to get worse, someone has some idea of how I can restructure my search for user by bringing names similar users and not exactly typing the full name?
php client 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>
Can you explain better what you mean by "the page takes a while to load"? how many entries are in SQL? the search looks pretty simple.
– Sergio
I enter the page and it is locked until all users in my select, I have more than 2,000 users... I need to elaborate a search algorithm by user name and at the same time displaying suggestions of names as I type in the search
– Rafael Assmann
So the best is to have a search that will fetch info via ajax as it writes. Like Google.
– Sergio
The case that you cited of how to bring through names similar users without typing the whole name you can use the LIKE of SELECT if I understand correctly, ex:
SELECT * FROM tabela WHERE campo LIKE '%Rafa%'
In this case search for bank records that start, end or contain Rafa– Tiago Boeing
Now, for this autocomplete suggestion to happen automatically as the user type you will need to use AJAX or Jquery, there is a nice plugin that you can do this: http://www.devbridge.com/sourcery/components/jquery-autocomplete/
– Tiago Boeing
@Tiagoboeing Thank you very much! I checked the link of the autocomplete, I found very cool but it has a lot of content that I did not understand very well, you have as an example of how I can use this jquery autocomplete ?
– Rafael Assmann
You can use it to replace fields
<select>
for example. The user starts typing some values and in real time the autocomplete filters the results in a list, in the example they are in the filecountries.js
(https://github.com/devbridge/jQuery-Autocomplete/blob/master/scripts/countries.js). You can download the official project on github, including some templates, apparently is easy to edit. https://github.com/devbridge/jQuery-Autocomplete– Tiago Boeing
There are other autocomplete plugins with AJAX, jQuery, etc. Just take a look. I put this plugin as an example because I found it interesting and maybe it can meet your needs according to the question asked. I’m glad you helped!
– Tiago Boeing
@Tiagoboeing helped a lot, thank you very much, I was able to import my code, but I’m lost on how to find the id and name of the clients in my database instead of the region that is in the file countries.js, can help me ??
– Rafael Assmann