ineedhelpbigtime Posted January 10, 2009 Share Posted January 10, 2009 Hello again, i am struggling to modify a nifty auto suggest function. It came hardcoded with an array, and i need to modify it to work form my DB. Could someone have a look for me? The code i am using is from http://www.brandspankingnew.net/specials/ajax_autosuggest/ajax_autosuggest_autocomplete.html. My cut down version of the php is as follows: <?php include(inc/connect.php); // assign search input and set limit. $input = strtolower( $_GET['input'] ); $len = strlen($input); $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 0; // results $getName_sql = "SELECT username FROM users WHERE username LIKE '%$input%' OR names LIKE '%$input%'"; $getName = mysql_query($getName_sql); // I have tried a number of things to convert the output of the above query into something that the script can handle, but probably incorrect methods... $aUsers = array( "Ädams, Egbert", "Altman, Alisha", "Luke, Stagg" ); $aResults = array(); $count = 0; // If stringlength... if ($len) { for ($i=0;$i<count($aUsers);$i++) // counts... { // 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) { $count++; $aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]) ); } if ($limit && $count==$limit) break; } } 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 "]}"; } ?> I have added my search query but i am unable to output the query results in a format that the rest of the code will accept (and i'm assuming the rest of the code will accept it...). The code above currently is still working from the 3 names specified in the manual array. As always your help is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/140285-autosuggest-implementation-hardcoded-array-mysql-results-help-needed/ Share on other sites More sharing options...
ineedhelpbigtime Posted January 11, 2009 Author Share Posted January 11, 2009 I have now been given the code to make the php work... but i am getting one weird error in firefox error console: Warning: Error in parsing value for property 'background-image'. Declaration dropped. Source File: http://localhost/autosuggest_v2.1.3/css/autosuggest_inquisitor.css Line: 137 This is the only error, which leads me to believe the SQL is now working... But the autosuggest is not. Any suggestions? I desperately need to get the auto suggest working, if anyone has any easier tutorials on how to implement autosuggest please let me know. Quote Link to comment https://forums.phpfreaks.com/topic/140285-autosuggest-implementation-hardcoded-array-mysql-results-help-needed/#findComment-734439 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.