php - Order by using selected values from drop down list without using form -


searched many options find easy solution can sort results din't find any. want order displayed results selected drop down values. don't want use "form". want other way sort it.

<div class="col-lg-2"> <label class="margin-bottom:25px;" style="margin-left:75px;"> sort by: <label> </div> <div class="col-lg-2">     <select class="form-control" id="sortby" name="sortby">         <option selected value="id">id</option>         <option value="name">name</option>         <option value="source">source</option>         <option value="location">location</option>     </select> </div> 

the above drop down list. below our $sql initial query :

$condition = implode(' , ', $query); $sql = " select candidate.cand_number,candidate.cand_fname,candidate.cand_source,candidate_contact.cand_location candidate ".$join.' '.$condition; 

now have tried far ,but seems wrong.

if($_post['sortby']=="id") {  $sql = " select candidate.cand_number,candidate.cand_fname,candidate.cand_source,candidate_contact.cand_location candidate ".$join.' '.$condition." order candidate.cand_number asc"; }  if($_post['sortby']=="name") {  $sql = " select candidate.cand_number,candidate.cand_fname,candidate.cand_source,candidate_contact.cand_location candidate ".$join.' '.$condition." order candidate.cand_fname asc"; }  if($_post['sortby']=="source") {  $sql = " select candidate.cand_number,candidate.cand_fname,candidate.cand_source,candidate_contact.cand_source candidate ".$join.' '.$condition." order candidate.cand_source asc"; }  if($_post['sortby']=="location") {  $sql = " select candidate.cand_number,candidate.cand_fname,candidate.cand_source,candidate_contact.cand_source candidate_contact ".$join.' '.$condition." order candidate.cand_location asc"; } 

asc- ordering in ascending order;

my jquery/ajax script-

<script>         $(document).ready(function(){             // each time change sort list, send ajax request             $("#sortby").change(function(){                 $.ajax({                     method: "post",                     url: "viewcandidate.php",                     data: { sortby:$("#sortby").val() }                 })                 // copy ajax response in table                 .done(function( msg ) {                     $("#list").html(msg);                 });             });         });     </script>     //even tried $(window).load(function){.....but no result. 

what wrong not working me ? dont want use form. suggest me easy solution.

firstly here wrong...

<select class="form-control" id="sortby" name="sortby">     <option selected value="id">id</option>     <option value="relevance">name</option><!-- value ???-->     <option value="name">source</option><!-- value ???--> </select> 

would

<select class="form-control" id="sortby" name="sortby">     <option selected value="id">id</option>     <option value="name">name</option>     <option value="source">source</option> </select> 

as compare $_post['sortby']=="name" , $_post['sortby']=="source"


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -