如何获取一个php会话变量并在ssp的where子句中使用它来获取带有datatable的单个ligne记录

问题描述:

I spend hours on searching for a solution to filter table and show only the ligne recordes where column equal the value of session variable for that i try this:

i called only one variable session into the server-response.php on head of file : require_once("./_inc/config.php") and i have stocked this session variable to a second variablea as next: $CodeApogee = $_SESSION["code_apogee"]; and this variable i used it as condition in the $sWhere clause as next :

       /* 
        * Script:    DataTables server-side script for PHP and MySQL
        * Copyright: 2012 - John Becker, Beckersoft, Inc.
        * Filtering
        * NOTE this does not match the built-in DataTables filtering which does it      
        * word by word on any field. It's possible to do here, but concerned about efficiency
        * on very large tables, and MySQL's regex functionality is very limited
        */
        $CodeApogee = $_SESSION['code_apogee']; //changes

        $sWhere = "notes.code_apogee=".$CodeApogee." ";
        if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" ) {
            $sWhere = "WHERE (notes.code_apogee=".$CodeApogee.")"; //changes
            for ( $i=0 ; $i<count($columns) ; $i++ ) {
                if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" ) {
                    $sWhere .= "`".$columns[$i]."` LIKE :search OR ";
                }
            }
            $sWhere = substr_replace( $sWhere, "", -3 );
            $sWhere .= ')';
        }

_ and my data.php file look like:_

$(document).ready(function() {
$('#note').dataTable( {
 "aProcessing": true,
 "aServerSide": true,
 "ordering": false,
 "searching": true,
 "paging":   true,
 responsive: true,
 "ajax": { 
    url: "server-response.php",
    type: 'POST'
}
});
});
</script>
</head>
<body class="note">
<table id="note" class="display responsive table table-striped table-hover dt-responsive" cellspacing="0" width="100%"> 
<thead>
<tr>
<th class="all" >Code Apogee</th>
<th class="min-phone-l" >Nom</th>
<th class="min-phone-l">Prenom</th>

Also the datatable style wont run like i configure it.

Retrieve Session from php and use in DataTable as query variable
Please help me i hav read this post and i cant figure out how to do the same,

Here's the firebug screenshot one record has been filtred out but no data comes with from the table. enter image description here

Firstly, Make sure that, you used session_start() in both page from where you setting a value in session and where you used in this session variable.

Secondly, change this

$CodeApogee = $_SESSION['code_apogee'];
 to 
$CodeApogee =  "'".$_SESSION['code_apogee']. "'";