title: Order by using selected values from drop down list without using form
body: <p>Searched many options to find some easy solution where i can sort my results but din't find any.
  I want to order the displayed results by selected drop down values. I don't want to use "form". Want the other way to sort it.</p>
  
  <pre><code>&lt;div class="col-lg-2"&gt;
  &lt;label class="margin-bottom:25px;" style="margin-left:75px;"&gt; Sort by: &lt;label&gt;
  &lt;/div&gt;
  &lt;div class="col-lg-2"&gt;
      &lt;select class="form-control" id="sortby" name="sortby"&gt;
          &lt;option selected value="ID"&gt;ID&lt;/option&gt;
          &lt;option value="Name"&gt;Name&lt;/option&gt;
          &lt;option value="Source"&gt;Source&lt;/option&gt;
          &lt;option value="Location"&gt;Location&lt;/option&gt;
      &lt;/select&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The above is my drop down list.
  The below is our $sql initial query :</p>
  
  <pre><code>$condition = implode(' AND ', $query);
  $sql = " SELECT candidate.cand_number,candidate.cand_fname,candidate.cand_source,candidate_contact.cand_location FROM candidate ".$join.' where '.$condition;
  </code></pre>
  
  <p>Now we have tried to this so far ,but it seems something is wrong.</p>
  
  <pre><code>if($_POST['sortby']=="ID")
  {
   $sql = " SELECT candidate.cand_number,candidate.cand_fname,candidate.cand_source,candidate_contact.cand_location FROM candidate ".$join.' where '.$condition." order by candidate.cand_number asc";
  }
  
  if($_POST['sortby']=="Name")
  {
   $sql = " SELECT candidate.cand_number,candidate.cand_fname,candidate.cand_source,candidate_contact.cand_location FROM candidate ".$join.' where '.$condition." order by candidate.cand_fname asc";
  }
  
  if($_POST['sortby']=="Source")
  {
   $sql = " SELECT candidate.cand_number,candidate.cand_fname,candidate.cand_source,candidate_contact.cand_source FROM candidate ".$join.' where '.$condition." order by candidate.cand_source asc";
  }
  
  if($_POST['sortby']=="Location")
  {
   $sql = " SELECT candidate.cand_number,candidate.cand_fname,candidate.cand_source,candidate_contact.cand_source FROM candidate_contact ".$join.' where '.$condition." order by candidate.cand_location asc";
  }
  </code></pre>
  
  <p>asc- Its for ordering in ascending order;</p>
  
  <p>My jquery/ajax script-</p>
  
  <pre><code>&lt;script&gt;
          $(document).ready(function(){
              // Each time you change your sort list, send AJAX request
              $("#sortby").change(function(){
                  $.ajax({
                      method: "POST",
                      url: "viewcandidate.php",
                      data: { sortby:$("#sortby").val() }
                  })
                  // Copy the AJAX response in the table
                  .done(function( msg ) {
                      $("#list").html(msg);
                  });
              });
          });
      &lt;/script&gt;
      //even tried with $(window).load(function){.....but no result.
  </code></pre>
  
  <p>What is wrong as this is not working for me ? I dont want to use form. Suggest me some easy solution.</p>