title: jQuery Autosuggest with mySQL and PHP
body: <p>I'm setting up an autosuggest where a person can enter a state and get referred to a page on my website.  I am linking this to a database because once I get this simple example working I will have 50,000 places in a database to look up.  Right now I just have states.</p>
  
  <p>Everything works good except that when a user selects a state from the list, the name filled out in the box is the url link that I am sending them too rather than the correct label.  (But I am still going to send them to a url.)  Its a small point but it just doesn't look right.  Any ideas?</p>
  
  <pre><code>jQuery(document).ready(function($){
      $('#searchbox').autocomplete({
          source:'suggest.php', 
          minLength:1,
          select: function(event, ui) {
              $( "#searchbox" ).val( ui.item.label );
              var url = ui.item.value;
              if(url != '#') {
                  window.location.href = url;
              }
          },
          html: true,
          open: function(event, ui) {
              $(".ui-autocomplete").css("z-index", 1000);
          }                   
      });
  });
  </code></pre>
  
  <p>The php returns both the web link and the label being searched:</p>
  
  <pre><code>while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
  {
      $data[] = array(
          'label' =&gt; $row['Label'],
          'value' =&gt; $row['Link']
      );
  }
  </code></pre>
  
  <p>Here is the example running <a href="http://www.towncharts.com/newtest.html" rel="nofollow">1</a></p>