Pass more than one select dropdowns value to filter table ( via ajax/php)

Pass more than one select dropdowns value to filter table ( via ajax/php)

phoenixstuphoenixstu Posts: 5Questions: 2Answers: 0

Hi there,

I'm following this tutorial but trying to make it work with more than 1 select dropdowns:

https://www.webslesson.info/2017/07/datatables-individual-column-searching-using-php-ajax-jquery.html

I can't work out how to pass 2 select dropdown values via ajax to filter the table

select 1: qualtype
select 2: country

HTML ajax part I'm struggling with:

"ajax":{
   
    type:"POST",
    data:{
is_qualtype:is_qualtype,is_country:is_country}

In fetch.php


if(isset($_POST["is_qualtype"])) { $query .= " WHERE "; $query .= "qualification_type = '".$_POST["is_qualtype"]."' "; } if(isset($_POST["is_country"])) { $query .= " WHERE "; $query .= "country = '".$_POST["is_country"]."' "; }

The value is being passed through to fetch.php but it goes to 'is_qualtype' query not 'is_country' query which is incorrect.

Appreciate any help or direction!

Thanks
Greg

Answers

  • kthorngrenkthorngren Posts: 21,169Questions: 26Answers: 4,922

    There is nothing obvious from your code snippets that looks to be a problem. If you want to post a link to your page we can take a look to help debug. Otherwise you can use console.log or the the browser's debugger to follow both is_qualtype and is_country through your code to validate their values. You can use the browser's network inspector to see what values are sent via the ajax request.

    Kevin

  • phoenixstuphoenixstu Posts: 5Questions: 2Answers: 0

    Thanks for this, I worked out I wasn't passing the information using the on selected function.

     $(document).on('change', '.selectbox', function(){
      var qualtype = $('#qualtype').val();
      var country = $('#country').val();
    
    if(qualtype != '' && country != '')
      {
    
    load_data(qualtype, country)
    
    }
    
     });
    
    

    I'm a lot further on now but have another error unrelated which I will post in another thread.

    Thanks

This discussion has been closed.