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

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看