title: Autocomplete, PHP, JS, AJAX MySql
body: <p>I am new to Ajax. I have Mysql database table</p>
  
  <pre><code>city_list 
  
  id | city | province | country
  ------
  1 | Calgary | AB | Canada
  ------------------- 
  2 | Edmonton | AB | Canada
  -------------------- 
  3 | Toronto | ON | Canada
  -------------------
  </code></pre>
  
  <p>and so on.....</p>
  
  <p><code>index.php</code>:</p>
  
  <pre><code>$('#city').autocomplete(
      {
          source: "searchSuggest.php",
          minLength: 3
      });
  </code></pre>
  
  <p>I want to create auto complete for the below field</p>
  
  <pre><code>&lt;input type="text" id="city" name="city"&gt;
  </code></pre>
  
  <p><code>serchSuggest.php</code>:</p>
  
  <pre><code>&lt;?php
  include('db_connect.php');
  if($_REQUEST)
  {
      $city   = $_REQUEST['city'];
      $city = ucwords($city);
      $return_results = array();
      $query = "select city, province from city_list where city LIKE '$city%'";
      $results = mysql_query( $query) or die('ok');
      $row=mysql_fetch_array($results);
          $i=0;
          while($row)
          {
          $i=$i+1;
          $return_results[$i] = $row;
          $row=mysql_fetch_array($results);
          }
          print json_encode($return_results);
  }    
  ?&gt;
  </code></pre>
  
  <p>This Works fine.</p>
  
  <pre><code>var tags = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ];
              $( "#city" ).autocomplete({
                  source: function( request, response ) {
                          var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
                          response( $.grep( tags, function( item ){
                          return matcher.test( item );
                          }) );
                          }
                      });
  </code></pre>
  
  <p>How Can i change source to the the database table city_list. Thanks.</p>