Autosuggest box not working correctly using json and php?

Experts,

I am using the following autosuggest code:
http://www.brandspankingnew.net/specials/ajax_autosuggest/ajax_autosuggest_autocomplete.html

Have been able to successfully tap into my database using the JSON method, however, when I type something into the autosuggest field, the auto suggestions do not change with the different key presses.

For example: When I type in any letter to start the auto-suggest, I always get the first 4 results in my database.  No matter what I type, I always get the same results.  If my letter matches a letter in the results, it changes color as expected. If I make another key press, the auto suggest box does not pair down the results, it just continues to show my first 4 db entries, and colors matching letters.

Can anyone help?  This is my code so far:
test.html

<body>

<div>
<form method="get" action="" class="asholder">
	<small style="float:right">Hidden ID Field: <input type="text" id="testid" value="" style="font-size: 10px; width: 20px;" disabled="disabled" /></small>
	<label for="testinput">Person</label>
	<input style="width: 200px" type="text" id="testinput" value="" /> 
	<input type="submit" value="submit" />
</form>
</div>
<script type="text/javascript">
	var options = {
		script:"dynamic_content.php?json=true&limit=4&",
		varname:"input",
		json:true,
		shownoresults:false,
		maxresults:4,
		callback: function (obj) { document.getElementById('testid').value = obj.id; }
	};
	var as_json = new bsn.AutoSuggest('testinput', options);
</script>

</body>

/////////////////////

dynamic_content.php

header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
	header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
	header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header ("Pragma: no-cache"); // HTTP/1.0
	
	
	
	if (isset($_REQUEST['json']))
	{
		header("Content-Type: application/json");
	
			$sql="SELECT * FROM members";
			$data = mysql_query($sql);
			echo "{\"results\": [";
			while($results = mysql_fetch_array($data)){
			echo "{\"id\": \"".$results['id']."\", \"value\": \"".$results['LastName'].", ".$results['FirstName']."\", \"info\": \"".$results['NUID']."\"},";
			}
			echo'{ id: "", value: "", info: "" }';
		echo "]}";
}

////////////////////////////////////////////////////

the bsn.AutoSuggest_2.1.3.js file has not been modified.

Open in new window

evibesmusicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

evibesmusicAuthor Commented:
@All:

I found out that if I limit the number of query results the function works properly but, I don't want to limit the number of query results, I want to be able to select from all entries in the db.
0
hieloCommented:
then try putting a large number in the options
maxentries:10000
0
Richard DavisSenior Web DeveloperCommented:
Looking at your SELECT statement, I noticed that you are never actually creating a WHERE clause by which to filter the select on. I do something similar on one of my custom admin systems I developed, only not with AJAX, but same principle.

I would modify your code so that the ajax call is sending the contents of the input box as each character is typed in and then in the dynamic_content.php, I would scrub the value passed in, then create a WHERE clause in the SELECT that uses a LIKE condition with %$value% as the like qualifier.

This will reduce the query's dataset to a much smaller number of returned records while also giving you back the data that specifically applies to the search criteria that you're wanting to have returned.

Hope this helped.

~A~
0
hieloCommented:
change:
if (isset($_REQUEST['json']))

to:
if (isset($_REQUEST['input']))


AND also:
 $sql="SELECT * FROM members";

to:
 $sql="SELECT * FROM members WHERE `lastName` LIKE '" . mysql_real_escape_string($_REQUEST['input']) . "%' ";

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.