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: --

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
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
	$aUsers = array(
		"Adams, Egbert",
		"Altman, Alisha",
	$aInfo = array(
	$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 "]}";
		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 = {
		callback: function (obj) { document.getElementById('testid').value =; }
	var as_json = new bsn.AutoSuggest('testinput', options);
	var options_xml = {
		script: function (input) { return "test.php?input="+input+"&testid="+document.getElementById('testid').value; },
	var as_xml = new bsn.AutoSuggest('fram1', options_xml);
	var as_xml = new bsn.AutoSuggest('fram2', options_xml);
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