So I've put together a search feature which searches as you type and displays the result in the text field but now the catch is that it won't let me delete easily and is 'thinking' too fast. Any ideas on how to slow this down?
<script>
$(document).ready
(function()
{
$("#tag").keyup
(function()
{
var tag= $(this).val();
if(tag!='')
{
$.ajax(
{
type: "GET",
url: "autocomplete.php",
data: "q=" + tag,
cache: false,
success: function(result)
{
$("#tag").val(result);
}
}
);
}
return false;
}
);
}
);
</script>
and then this
<?php
$q_incoming=$_GET['q'];
//$my_data=mysql_real_escape_string($q_incoming);
$mysqli=mysqli_connect('localhost','XXXXXXX','XXXXXXXX','XXXXX') or die("Database Error");
$sql = "SELECT auto_complete_suggestions FROM auto_complete WHERE auto_complete_suggestions LIKE '$q_incoming%' LIMIT 0,1";
$result = mysqli_query($mysqli,$sql) or die(mysqli_error());
if($result)
{
while($row=mysqli_fetch_array($result))
{
echo $row['auto_complete_suggestions']."\n";
}
}
?>
The thing I think is happening is that if I type "he" it prompts "help" but when i delete the "p" it's going to prompt again since it has "hel" to search on. Any ideas on how to allow it to delete as well as slow the querying down so that you can type a letter at a reasonable typing pace? I could fidget with a timing function or maybe tell it to ignore after a delete?
Thanks!