Question : Autocomplete

I am using an ajax autoccomplete  script to populate an input box. I am running into two issues.

1. I do not know how to retrieve the id value and place it into the input box value.
2. I am able to display the first name but not sure how to get the last name "last" to display too.

My scripts are below..thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
<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);
?>

Answer : Autocomplete

Random Solutions  
 
programming4us programming4us