jQuery Autocomplete Error in WordPress

I am trying to implement an auto complete feature in wordpress but am a getting the following error:

Fatal error: Call to undefined method stdClass::get_results() in >’…get_airports.php’ on line 9

Read More

The following is my code:

html: <input type="text" name="airports" id="airports" />

php: global $wpdb;

$q = strtolower($_GET["q"]);
if (!$q) return;

$wpdb->iata_airport_codes = $wpdb->prefix . "iata_airport_codes"; 
$airport_list_db = $wpdb->
get_results("SELECT * FROM `wp_iata_airport_codes` WHERE `airport` LIKE '%$q%' LIMIT   0,15");

foreach($airport_list_db as $airports){

 echo $airports->airport . "n";

}

js: jQuery(document).ready(function() {
$("#airports").autocomplete("get_airports.php", {
    width: 230,
    matchContains: true,
    selectFirst: false
});
 });

any help will be much appreciated thanx.

Related posts

Leave a Reply

2 comments

  1. solved it!!! I connected to db directly using mysql_connect then used mysql_fetch_array($result, MYSQL_ASSOC) to loop though the result and display it. That worked but still dont know where the error was coming from probably because I put the ‘get_airports.php’ outside of wordpress in the root dir of the site. Thanx for all the help.