sekundes99 Posted January 4, 2011 Share Posted January 4, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/223421-auto-complete-site-search/ Share on other sites More sharing options...
MadTechie Posted January 5, 2011 Share Posted January 5, 2011 looks find to me.. what do you mean it failed! what actually happened ? Error message ? Quote Link to comment https://forums.phpfreaks.com/topic/223421-auto-complete-site-search/#findComment-1155052 Share on other sites More sharing options...
sekundes99 Posted January 5, 2011 Author Share Posted January 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/223421-auto-complete-site-search/#findComment-1155188 Share on other sites More sharing options...
MadTechie Posted January 5, 2011 Share Posted January 5, 2011 make sure the other code is in a PHP file (with the php extension) Quote Link to comment https://forums.phpfreaks.com/topic/223421-auto-complete-site-search/#findComment-1155209 Share on other sites More sharing options...
jake2891 Posted January 5, 2011 Share Posted January 5, 2011 the codes using jquery have you downloaded and installed that seeing as you just copied the code from somewhere? Quote Link to comment https://forums.phpfreaks.com/topic/223421-auto-complete-site-search/#findComment-1155212 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.