troubleshooting Question

How do I make this bsn.autosuggest script, from a javascript into a SQL working one?

Avatar of verm1n
verm1n asked on
JavaScriptXMLMySQL Server
5 Comments1 Solution1804 ViewsLast Modified:
Hello fellas,
Im trying to use a autosuggest searchscript on my site, and im currently interested in this one: http://www.brandspankingnew.net/archive/2006/08/ajax_auto-suggest_auto-complete.html --

But the thing is, that this is a javascript with some pre-written answers..

Instead of that, I want to use it in my SQL database, Anyone know how to do this?

The standard version from the site uses this methods, posted into the CODE below. I have no really clue where to being.

Further notice.. I really appreciate some help here!
File: test.php
 
<?php
 
/*
note:
this is just a static test version using a hard-coded countries array.
normally you would be populating the array out of a database
 
the returned xml has the following structure
<results>
	<rs>foo</rs>
	<rs>bar</rs>
</results>
*/
 
	$aUsers = array(
		"Adams, Egbert",
		"Altman, Alisha",
	);
	
	
	$aInfo = array(
		"Bedfordshire",
		"Buckinghamshire",
	);
	
	
	$input = strtolower( $_GET['input'] );
	$len = strlen($input);
	
	
	$aResults = array();
	
	if ($len)
	{
		for ($i=0;$i<count($aUsers);$i++)
		{
			// had to use utf_decode, here
			// not necessary if the results are coming from mysql
			//
			if (strtolower(substr(utf8_decode($aUsers[$i]),0,$len)) == $input)
				$aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) );
			
			//if (stripos(utf8_decode($aUsers[$i]), $input) !== false)
			//	$aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) );
		}
	}
	
	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");
	
		echo "{\"results\": [";
		$arr = array();
		for ($i=0;$i<count($aResults);$i++)
		{
			$arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"\"}";
		}
		echo implode(", ", $arr);
		echo "]}";
	}
	else
	{
		header("Content-Type: text/xml");
 
		echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?><results>";
		for ($i=0;$i<count($aResults);$i++)
		{
			echo "<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>";
		}
		echo "</results>";
	}
?>
 
File: index.php - the main file with all design ect..
 
 
<script type="text/javascript">
	var options = {
		script:"test.php?json=true&limit=20&",
		varname:"input",
		json:true,
		shownoresults:false,
		maxresults:10,
		callback: function (obj) { document.getElementById('testid').value = obj.id; }
	};
	var as_json = new bsn.AutoSuggest('testinput', options);
	
	
	var options_xml = {
		script: function (input) { return "test.php?input="+input+"&testid="+document.getElementById('testid').value; },
		varname:"input"
	};
	var as_xml = new bsn.AutoSuggest('fram1', options_xml);
	var as_xml = new bsn.AutoSuggest('fram2', options_xml);
</script>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros