Loading mysql rows from PHP into autocomplete jquery -


<?php  $cuvant = (isset($_get['cuvant']) ? $_get['cuvant'] : ''); // word want search box $sql = "select cuvant cautare cuvant like'".$cuvant."%'order nr_cautari desc limit 0,6"; // search word in table database ?> <script> $(function() {     var cuvinte=['<?php          $resursa = mysql_query($sql);     ?>'];     $( "#cautare" ).autocomplete({         // #cautare id of search box         source: cuvinte     }); }); </script> 

i'm trying make auto-completer jquery, , have code in index.php page. don't know how fix issue: when try search on page, nothing happens.

assuming using jquery autocomplete: https://jqueryui.com/autocomplete/

i believe variable contains values has valid json. doing mysql_fetch_assoc() going return php array looks each row:

array(   'cuvinte' => "something" ); 

so, assuming there multiple rows returned query, think need this:

<script>   $(function() {     var cuvinte=        <?php          $result = mysql_query($sql);             while ($row = mysql_fetch_assoc($result)) {           $resursa[] = $row['cuvant'];         }         echo json_encode($resursa);     ?>;     $( "#cautare" ).autocomplete({// #cautare id of search box       source: cuvinte     });   });   </script> 

basically, takes result of query, loops through rows, , builds temporary array. last step take array , let php turn json you.