Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82505

passing a variable to DataTables server side processing

$
0
0

I have a dropdown box that I use to get a variable. Then I want to pass that variable to DataTables server side processing. The PHP page I use as the URL will take the variable to fill in a query. But I haven't been successful in passing this variable.

$('#medProcDataList').change(function() {
        
        //fetch variable
        var $selectedValue = $(this).val();
        var arrSelVal = $selectedValue.split(":");
        $code = arrSelVal[0]; //get hospital code

//Then I want to pass the variable to DataTables

$('#results').DataTable( {
            "processing": true,
            "serverSide": true,
            data: {code: $code },
            "ajax": "php/getDataForCode.php",
             "ajax": {
            "url": "scripts/server_processing.php",
            "data": $code
            columns: [
                    { title: "Hospital", data: "hospital_name" },
                    { title: "Description", data: "raw_description" },
                    { title: "Insurer", data: "full_payer_name" },
                    { title: "Insurer type", data: "play_type"},
                    { title: "You Pay", data: "price" }
            ]
        } );
}//end function

PHP:

$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (mysqli_connect_errno()) {
        printf("Connect failed: %s", mysqli_connect_error());
        exit;
}
mysqli_set_charset($db, 'utf8'); //important! or it won't echo the array

    if( $_POST) {
        $code = mysqli_real_escape_string($db, $_POST['code']);
        $data = array();
        $q = "SELECT hospital_name, raw_description, full_payer_name, plan_type, format([price], 'N0') FROM `hospital_transparency_data` where procedure_codes = '" . $code . "' order by hospital_name, full_payer_name";
        $result = $db->query($q);
        while($row = $result->fetch_array(MYSQLI_ASSOC)) {
            //Add this row to the reply
            $data[] = $row;
        }
        
        
        $db->close();
        echo json_encode($data);
    
} //if POST

My query yields no results, so I know

What am I doing wrong please?

Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide


Viewing all articles
Browse latest Browse all 82505

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>