title: PHP Mysql query - allow user to filter results
body: <p>I have a webpage setup with php and mysql.  I've figured out how to run a query which pulls from mysql and prints the results in a table on the webpage.</p>
  
  <p>Now I want to allow the user to filter the results 1 column at a time.  No typing in needed, a pull down menu which shows options from the database would be fine.  E.g. in my code below, they can filter either by name, date, or state.  Initially the webpage shows all results.</p>
  
  <p>Filtering multiple columns at a time would be nice, but not required.  Ideally I envision dropdowns for each column where when the user selects the option, the results update. I would also prefer to not have to create separate webpages, but if I need to that's fine. </p>
  
  <p>My question is: What should I use to accomplish this as simply and as easily as possible?
  I am hoping there is a development tool which makes this an easy task.  Should I just use HTML get/post forms?  Or Ajax? Or Javascript? RubyonRails?  Or?  Any specific advice on what features within these resources I should use would be helpful also, because I am not familiar with Javascript / Ajax / Ruby, but I am open to diving into it if it has some good built in functionality to do this with.  </p>
  
  <p>Below is a sample of my code.  The query is filtering results because I was testing to make sure I could execute a query with a variable, but initially it should just do a simple select * from table.</p>
  
  <pre><code>    &lt;?php 
      print "Filter Results by Name, Date or State";
  
      $connection = connectdb("mysql");
  
      $state = "Kentucky";    
  
      $querytext = sprintf("SELECT * FROM tablename
          WHERE state = '%s'
          ",
          mysql_real_escape_string($state));
  
      $queryresult = getqueryresult($querytext,$connection);
  
      $tableid = "mytablestyle";
  
      printqueryresult($tableid,$queryresult);
  
      //close connection
      mysql_close($connection);
      ?&gt;
  </code></pre>