dongshanyan0322 2017-05-22 17:12
浏览 70
已采纳

如何获取一个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

  • 写回答

1条回答 默认 最新

  • dtrj74376 2017-05-22 17:20
    关注

    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']. "'";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能