title: How to call MySQL source data for jQuery autocomplete?
body: <p>I am using jQuery autocomplete, and want to have a separate PHP file to house the data, instead of creating a variable (i.e. var availableTags = ["Red", "Orange", "Yellow", "Green, "Blue"]).</p>
  
  <p>However, when doing this, the autocomplete will continually display all of the available options, and not filter out what the user types in.</p>
  
  <p>Any ideas?</p>
  
  <p>Javascript:</p>
  
  <pre><code>$(document).ready(function() {
  
      $( ".autocomplete" ).autocomplete({
              source: "../../db/autocomplete_list.php"
      });
  
  });
  </code></pre>
  
  <p>autocomplete_list.php</p>
  
  <pre><code>require_once('../includes/connect.php');
  $dbh = connect(DB_HOST,DB_USER,DB_PASSWORD,CM_DATABASE);
  
  $colors = '[';
  
  $sth = $dbh-&gt;query ("SELECT * FROM constants 
                       WHERE category='Colors' 
                       ORDER BY display");
  
  while ($row = $sth-&gt;fetch ()) { 
  
      $colors.= '"'.$row[value].'", '; 
  
  }
  
  $colors = rtrim($colors, ', ');
  
  $colors .= ']';
  
  print $colors;
  </code></pre>
  
  <p>execution of autocomplete_list.php</p>
  
  <blockquote>
    <p>["Red", "Orange", "Yellow", "Green, "Blue"]</p>
  </blockquote>
  
  <h1>EDIT:</h1>
  
  <p>Have updated my autocomplete_list.php file to the following.  However, now the autocomplete isn't displaying my values.  If I check the response in FireBug, it is showing the results correctly, it just appears that they aren't being passed back to the autocomplete.</p>
  
  <pre><code>require_once('../includes/connect.php');
  $dbh = connect(DB_HOST,DB_USER,DB_PASSWORD,CM_DATABASE);
  
  if(isset($_GET['term'])) {
      $mysearchString = $_GET['term'];
  }
  
  $sth = $dbh-&gt;query("SELECT category, value, display FROM constants 
                      WHERE category = 'COLORS' AND value LIKE '$mysearchString%'
                      ORDER BY display");
  
  while ($row = $sth-&gt;fetch ()) { 
      print $row['display']."\n";         
  }
  </code></pre>