Problem with Autocomplete and mysql

Problem with Autocomplete and mysql

Good morning,

i have got a problem with jquery ui autocomplete. I use mysql, json and php as source for my autocomplete. If i wirte a word in autocomplete widget it will view all entries.

  1. // Conect json.php
  2.  $sql = "SELECT user_name FROM user ORDER BY user_id";
     $mysql->query($sql);
     
     while ($row = $mysql->fetch_array()) {
      $data[] = array('label' => $row['user_name']);
     }
     
     echo json_encode($data);






 The Php File shows me: [{"label":"53343"},{"label":"53773"},{"label":"53773"},{"label":"53773"},{"label":"53773"},{"label":"70736"},{"label":"79353"},{"label":"40231"},{"label":"47445"},{"label":"47475"},{"label":"53343"},{"label":"53773"}]

  1.   <script>
       $(function() {
       var availableTags = ["Theis", "Lapuse"];
        $("#tags").autocomplete({
         source: 'inc/json.php',
        });
       }); 
      </script>







 

If i copy data from json.php into an array like this it will works.

  1.   <script>
       var data = [{"label":"53343"},{"label":"53773"},{"label":"53773"},{"label":"53773"},{"label":"53773"},{"label":"70736"},{"label":"79353"},{"label":"40231"},{"label":"47445"},{"label":"47475"},{"label":"53343"},{"label":"53773"}];
       $(function() {
        $("#tags").autocomplete({
         source: data    });
       });