title: How to filter results in a table using URL parameters
body: <p>I'm trying to filter results on an HTML page by having the users select multiple options through dropdowns and text boxes.</p>
  
  <p>One example is filtering results within a 10 mile radius of a user.
  I have all the mechanics working but I'm not sure if I'm doing it right.</p>
  
  <p>So I have something like: 
  <a href="http://slickdeals.net/deals/tech/" rel="nofollow">http://slickdeals.net/deals/tech/</a></p>
  
  <p>Where the filter options are on the left of the page, people can filter by price range, rating and so on.
  So my first question is:
  Using javascript how would I start tacking filter options to the URL parameters?</p>
  
  <p>Right now I'm doing something like this:</p>
  
  <pre><code>$('#FilterLocation').on('change', function () {
      window.location.replace("?lat=" + place.geometry.location.lat() + "&amp;lng=" + place.geometry.location.lng());
  });
  $('#FilterPrice').on('change', function () {
      window.location.replace("?price=" + #FilterPrice.val());
  });
  </code></pre>
  
  <p>And the list goes on, as you can see if my filter list has 20 options, then my javascript code just starts growing and getting messy and ugly real quick.I know there has to be a better way to do this, how?</p>
  
  <p>Also second question. Once we get past the part where the URL goes into my controller, I'm using PHP.. I'm returning results by just doing WHERE queries in MySQL.</p>
  
  <p>So it looks like:</p>
  
  <pre><code>if ($State != '' &amp;&amp; $County != 'null' &amp;&amp; $isOnlineDeal != '') {
                  $query = "select * from posts where ...";
              } elseif ($State != '' &amp;&amp; $County != 'null' &amp;&amp;  $isOnlineDeal == '') {
                  $query = "select * from posts where ...";
              } elseif ($State != '' &amp;&amp; $County == 'null' &amp;&amp;  $isOnlineDeal == '') {
                  $query = "select * from posts where ...";
              } elseif ($State == '' &amp;&amp; $County == 'null' &amp;&amp;  $isOnlineDeal == '') {
                  $query = "select * from posts where ...";
              } elseif ($State != '' &amp;&amp; $County == 'null' &amp;&amp;  $isOnlineDeal == '') {
                  $query = "select * from posts where ...";
              } elseif ($State != '' &amp;&amp; $County != 'null' &amp;&amp;  $isOnlineDeal == '') {
                  $query = "select * from posts where ...";
              } elseif (&amp;&amp; $State == '' &amp;&amp; $County == 'null' &amp;&amp;  $isOnlineDeal != '') {
                  $query = "select * from posts where ...";
              } elseif ($State == '' &amp;&amp; $County == 'null' &amp;&amp;  $isOnlineDeal != '') {
                  $query = "select * from posts where ...";
              } elseif ($State != '' &amp;&amp; $County == 'null' &amp;&amp;  $isOnlineDeal != '') {
                  $query = "select * from posts where ...";
              } elseif ($State != '' &amp;&amp; $County != 'null' &amp;&amp;  $isOnlineDeal != '') {
                  $query = "select * from posts where ...";
              } elseif ($State != '' &amp;&amp; $County == 'null' &amp;&amp;  $isOnlineDeal != '') {
                  $query = "select * from posts where ...";
              } elseif ($State != '' &amp;&amp; $County != 'null' &amp;&amp;  $isOnlineDeal != '') {
                  $query = "select * from posts where ...";
              } else {
                  $query = "select * from posts";
              }
  </code></pre>
  
  <p>As you can see, I'm just doing a bunch of elseif's to check if variables are not empty and doing queries based on that. Once my filter options start getting bigger, this also grows.</p>
  
  <p>The specific data has been altered and isn't important, what I'm really trying to find out is:
  1. What's the best way to tack on url params to the url with javascript/jquery.
  2. Without having messy code, how do I filter those URL params in MySQL.</p>