title: Filtering data with a PHP, Jquery, AJAX form mechanism and data from Database
body: <p>I am trying to create a form that utilizes PHP and Jquery AJAX form submission mechanism which 'filters' data from a mySQL database.</p>
  
  <p>There are three dropdown bars in the form with a 'submit' button, which will 'filter' the data from the database. However, it is not a requirement of the user to want to filter from all the choices in the dropdowns - 'cuisine', 'pricing', 'location'. I need to create some sort of a query where if a dropdown is not being used, it is not used in the filter. </p>
  
  <p>Below is what I've started on. I've only made the 'cuisine' filter functional at the moment.  </p>
  
  <pre><code>if (isset($_GET['cuisine']) &amp;&amp; isset($_GET['pricing'])) {
      $cuisine = $_GET['cuisine'];
      $pricing = $_GET['pricing'];
      $location = $_GET['location'];
  
          if ($cuisine != 'Cuisine') { 
              $cuisineUse = true; 
          } else { $cusineUse = false; }
  
          if ($pricing != 'Price Range') { 
              $pricingUse = true; 
          } else { $pricingUse = false; } 
  
          if ($location != 'Location') { 
              $locationUse = true; 
          } else { $locationUse = false; }
  
  
  // Get all the data from the "example" table
  $result = mysql_query("SELECT * FROM restaurants 
  WHERE Cuisine='$cuisine'
  ORDER BY restaurantID
  ") 
  or die(mysql_error()); 
  </code></pre>
  
  <p>And the Jquery: </p>
  
  <pre><code>&lt;script&gt;
    /* attach a submit handler to the form */
    $("#searchForm").submit(function(event) {
  
      /* stop form from submitting normally */
      event.preventDefault(); 
  
      /* get some values from elements on the page: */
      var $form = $( this ),
          term = $form.find( 'input[name="cuisine"]' ).val(),
          url = $form.attr( 'action' );
  
      /* Send the data using post and put the results in a div */
      $.post( url, { s: term },
        function( data ) {
            var content = $( data ).find( '#content' );
            $( "#jsDiv" ).empty().append( content );
        }
      );
    });
  &lt;/script&gt;
  </code></pre>
  
  <p>P.S The user could also use two or more of the 'filters' at once. </p>