<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="jquery.autocomplete.js" type="text/javascript"></script>
<form method="post" action="">
<label for="text"></label>
<input type="text" name="users" value="" id="example" size="60" onChange="showUser(this.value)">
<script>
$("input#example").autocomplete("autocomplete-ajax.php");
</script>
<br/>
<input type="submit" value="submit">
</form>
<br />
<div id="txtHint"></div>
<?php
$link = mysql_connect('xxxxxxxxx', 'xxxxxxxxx', 'xxxxxxxxxx');
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
if (!mysql_select_db('xxxxxxxxxx'))
{
exit;
}
$text = mysql_real_escape_string($_GET['text']);
$sql = 'SELECT id,first FROM clients WHERE first LIKE "%'. $text . '%" LIMIT 5';
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result))
{
$posts[] = array($row['id'] => $row['first']);
}
echo json_encode($posts);
mysql_close($link);
?>
|