ng2-ui / auto-complete

Angular Auto Complete component and directive
http://ng2-ui.github.io/auto-complete/
MIT License
279 stars 124 forks source link

What format should my remote data be in? (PHP, MySQL) #204

Closed n0490b closed 6 years ago

n0490b commented 7 years ago

Here is my plnkr I am using my own remote data http://plnkr.co/edit/6wdUTD9zvzRtQ5EeM2jH

Currently I am using PHP and MySQL to query my database. If you enter "georgia" in full and look at the console you can see that two arrays are being returned with data but nothing shows up in the dropdown. Is my data in the correct format?

screen shot 2017-05-03 at 8 57 47 am

My PHP code

header("Access-Control-Allow-Origin: *");
ini_set('display_errors', 1);
require('Database.php');

$keyword=$_GET['term'];

 $sql="SELECT * FROM `jobSite` WHERE `province` LIKE :keyword;";
 $stmt = $pdo->prepare($sql);
 $stmt->bindValue(':keyword','%'.$keyword.'%');
 $stmt->execute(); 
while ($output = $stmt->fetch(PDO::FETCH_ASSOC)) {
          echo"<pre>".print_r($output,true)."</pre>";

}

smitthakkar96 commented 7 years ago

You must specify two keys in your data source id and value. Id represents the field through which you can uniquely identify the object and value is something that user will see. In your case it would be more convenient to have id = id and value = city.