title: JQuery Autocomplete from Database
body: <p>I need to to do autocomplete suggestion for my website and the data should be retrieved from database. I want to use JQuery autocomplete. here is my code but it doesn't work!
  This is my php file with the name of gethint.php:</p>
  
  <pre><code>&lt;?php
  require_once ('config.php');
  $q=$_REQUEST["q"]; 
  $sql="SELECT `fname` FROM `Property` WHERE fname LIKE '%$q%'";
  $result = mysql_query($sql);
  $json=array();
  
  while($row = mysql_fetch_array($result)) {
    $json[]=array(
    'value'=&gt; $row['fname'],
    'label'=&gt; $row['fname']
     );
     }
     echo json_encode($json);
    ?&gt;
  </code></pre>
  
  <p>and then this is my html file :</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt; 
  &lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"&gt;&lt;/script&gt;
  &lt;link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" /&gt;
   &lt;script type="text/javascript"&gt; 
   $(document).ready(function(){                  
   $("#hint").autocomplete({                        
   source:'gethint.php', 
   minLength:1                  
     }); 
     });        
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form class="sansserif" action="view.php" method="post"&gt;
  Name: &lt;input type="text" id="hint" name="hint" &gt;
  &lt;input type="submit" name="submit" value="View"&gt;
  &lt;/form&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>It took a lot of time but I couldn't find the problem. I was wondering if someone could help me.
  Thanks.</p>