dimanche 4 décembre 2016

Multi Select checkbox and dropdown option ajax

I have 4 type of filters for my table filter by Date(usingdatepicker), Company Name(using multiselect dropdown checkbox), Age(using dropdown option) and Term(using dropdown option). Only the filter for CompanyName which using multiselect dropdown checkbox is not working WHEN i put function for the Age filter in the condition.

            if(isset($_POST)) 
        {
        $COMPANYNAME = ($_POST);
        $COMPANYNAME = $_POST['COMPANYNAME'];
        $COMPANYNAME = is_array($COMPANYNAME) ? $COMPANYNAME : [$COMPANYNAME];
        $companiesParam = '\''. join("', '", $COMPANYNAME) . '\'';
        $fetch = "SELECT sl_iv.DOCDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME FROM `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.COMPANYNAME IN (".$companiesParam.") or sl_iv.DOCDATE <= '".$from."'";
        $results = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $fetch");   
        }

        if(!empty ($_POST['from']))
        {
        $from = $_POST['from'];
        $test = "SELECT sl_iv.DOCDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME From `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.DOCDATE <= '".$from."'";
        $results = mysqli_query($conn_connection,$test)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $test");
        }

        if(!empty($_POST["terms"] == "C.O.D"))
        {
        $terms = $_POST["terms"];
        $fetch = "SELECT sl_iv.DOCDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME FROM `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE payment_terms.terms = '".$terms."'";
        $results = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $fetch");
        }

        if(!empty($_POST["terms"] == "30 Days"))
        {
        $terms = $_POST["terms"];
        $fetch = "SELECT sl_iv.DOCDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME FROM `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE payment_terms.terms = '".$terms."'";
        $results = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $fetch");
        }

        if(!empty($_POST["terms"] == "60 Days"))
        {
        $terms = $_POST["terms"];
        $fetch = "SELECT sl_iv.DOCDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME FROM `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE payment_terms.terms = '".$terms."'";
        $results = mysqli_query($conn_connection,$fetch)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $fetch");
        }

        if(!empty($_POST["age"] == "10"))
        {
        $age = $_POST["age"];
        $frd=GetDateLess($age);
        $test = "SELECT sl_iv.DOCDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME From `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.DOCDATE  <= '".$frd."'   ";
        $results = mysqli_query($conn_connection,$test)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $test");
        }

        if(!empty($_POST["age"] == "30"))
        {
        $age = $_POST["age"];
        $frd=GetDateLess($age);
        $test = "SELECT sl_iv.DOCDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME From `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.DOCDATE  <= '".$frd."' ";
        $results = mysqli_query($conn_connection,$test)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $test");
        }

        if(!empty($_POST["age"] == "60"))
        {
        $age = $_POST["age"];
        $frd=GetDateLess($age);
        $test = "SELECT sl_iv.DOCDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME From `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.DOCDATE  <= '".$frd."'";
        $results = mysqli_query($conn_connection,$test)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $test");
        }

        if(!empty($_POST["age"] == "90"))
        {
        $age = $_POST["age"];
        $frd=GetDateLess($age);
        $test = "SELECT sl_iv.DOCDATE, payment_terms.terms, sl_iv.DOCNO, sl_iv.COMPANYNAME From `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id WHERE sl_iv.DOCDATE  <= '".$frd."' ";
        $results = mysqli_query($conn_connection,$test)or die("MySQL error: " . mysqli_error($conn_connection) . "<hr>\nQuery: $test");
        }

        function GetDateLess($mn)
        {
        $date=date_create(date("Y-m-d"));
        date_sub($date,date_interval_create_from_date_string($mn." days"));
        return date_format($date,"Y-m-d");
        }

        if (mysqli_num_rows($results) > 0) {
        while($row = mysqli_fetch_assoc($results)) {




Aucun commentaire:

Enregistrer un commentaire