Jump to content

Auto Complete Site Search


sekundes99

Recommended Posts

ive been searching a code for auto complete search and found this code on the net. but when i tried it, it failed. hope u can help me debug it.

<script type="text/javascript">
function lookup(inputString) {
	if(inputString.length == 0) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	} else {
		$.post("rpc.php", {queryString: ""+inputString+""}, function(data){
			if(data.length >0) {
				$('#suggestions').show();
				$('#autoSuggestionsList').html(data);
			}
		});
	}
} // lookup

function fill(thisValue) {
	$('#inputString').val(thisValue);
	setTimeout("$('#suggestions').hide();", 200);
}
</script>
<body>


<div>
	<form>
		<div>
			Type your county:
			<br />
			<input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" />
		</div>

		<div class="suggestionsBox" id="suggestions" style="display: none;">
			<img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
			<div class="suggestionList" id="autoSuggestionsList">
				 
			</div>
		</div>
	</form>
</div>

</body>

 

the other code is this --

 

<?php

$db = new mysqli('localhost', 'root' ,'', 'countries');

if(!$db) {

echo 'ERROR: Could not connect to the database.';

} else {

if(isset($_POST['queryString'])) {

$queryString = $db->real_escape_string($_POST['queryString']);

if(strlen($queryString) >0) {

$query = $db->query("SELECT value FROM countries WHERE value LIKE '$queryString%' LIMIT 10");

if($query) {

while ($result = $query ->fetch_object()) {

        echo '<li onClick="fill(\''.$result->value.'\');">'.$result->value.'</li>';

        }

} else {

echo 'ERROR: There was a problem with the query.';

}

} else {

 

}

} else {

echo 'There should be no direct access to this script!';

}

}

?>

 

when i input a letter or phrase on the search bar the other code pops on it.

Link to comment
https://forums.phpfreaks.com/topic/223421-auto-complete-site-search/
Share on other sites

well when i type something on the search bar, the *other* code will pop on the drop down button and not the searched name. thats why i said its not working. if you said that it work in your try then it must be my code or connection to my database is not working. thankx for the reply though.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.