本文介绍了数据表服务器端处理未在页面上显示输出并且条件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将数据表与Ajax一起用于服务器端处理。这是我指的链接


在页面上,仅显示正在处理



2)我尝试使用where条件,但也不能正常工作。


我尝试了以下代码

 < table id =" list" class = table table-striped table-bordered> 
< thead>
< tr class = table-column-heading
< th< / th>
< th> Email_Id< / th>
< th付款ID< / th>
个添加日期// th个
< th> Action< / th>
< / tr>
< / thead>
< tbody>
< / tbody>
< / table>
< script>
$(document).ready(function(){
var dataTable = $('#list')。DataTable({
processing:true,
serverSide:true,
ajax:{
url: fetch.php,
type: post,
// data:{'action ':'servicelist'}
}
});
});
< / script>

fetch.php

  $ table ='tbl_participantdetails'; 
$ primaryKey =‘pd_id’;
$ columns = array(
array('db'=>'pd_name','dt'=> 0),
array('db'=>'pd_email', 'dt'=> 1),
array('db'=>'paid','dt'=> 2),
array('db'=>'payment_id', 'dt'=> 3,),
array('db'=>'date_of_added','dt'=> 4,
'formatter'=> function($ d,$行){
返回日期('dm-Y',strtotime($ d));
}

);
require(’datatables / ssp.class.php’);
$ where =已付费= 1;

echo json_encode(
SSP :: simple($ _GET,$ pdo,$ table,$ primaryKey,$ columns,$ where)
);

这是我尝试的第二个选项,并且可以正常工作

 < table id =" list" class = table table-striped table-bordered> 
< thead>
< tr class = table-column-heading
< th< / th>
< th> Email_Id< / th>
thth付费/ th
< th付款ID< / th>
个添加日期// th个
< th> Action< / th>
< / tr>
< / thead>
< tbody>
< / tbody>
< / table>
$(document).ready(function(){
var dataTable = $('#list')。DataTable({
processing:true,
serverSide:true,
paging:true,
searchable:true,
ajax:{
url: fetch.php,
类型: post
},
语言:{
sLengthMenu: Show _MENU_,//删除条目文本
searchPlaceholder: Search ,
emptyTable:未找到记录,
搜索:
},
pageLength:25,
分页: true,
列:[{
数据: pd_name
},
{
数据: pd_email
},
{
data:已付费
},
{
data: payment_id
},
{
data: date_of_added
}
]
});
});

fetch.php

  $ stmt = $ pdo-> prepare(从tbl_participant中选择SELECT count(*),其中is_active = 1并且已付费= 1)); 
$ stmt-> execute();
$ totalRecords = $ stmt-> fetchColumn();
$ query ="从 tbl_participantdetails中选择 pd_id, pd_name, pd_pic, pd_email, payed, payment_id, date_of_added, is_active = 1且付费= 1 ;
try {
$ stmt = $ pdo-> prepare($ query);
$ stmt-> execute();
$ result = $ stmt-> fetchAll();

$ data [’data’] = [];
foreach($结果为$ row){
$ arr_result = array(
// id => $ i ++,
pd_name => ;< img src ='''。$ row ['pd_pic']。'''>'''。$ row ['pd_name'],
pd_email => $ row [' pd_email'],
已付费 => $ row ['paid'],
payment_id => $ row ['payment_id'],
date_of_added => $ row ['date_of_added']
);


$ data [’data’] [] = $ arr_result;
}
}
catch(PDOException $ e){
echo Error:" 。 $ e-> getMessage();
}

$ json_data = array(
draw => intval($ _ REQUEST ['draw']),
recordsTotal => ; intval($ totalRecords),
recordsFiltered => gt intval($ totalRecords),
data => $ data ['data']
);
echo json_encode($ json_data);
出口;


解决方案

尝试使用SSP :: complex()而不是SSP :: simple()


在PHP中也应该是SSP :: complex($ _ POST ...),因为您在ajax请求中使用了POST类型。


ajax中的url属性没有问题。


I am using data tables server-side processing with ajax. Here is the link I am referringhttps://datatables.net/examples/data_sources/server_side.html

I am getting issues which are as follows

1) I am getting the output on the network tab but it's not displaying on my page.

Network tab screenshot

On the page, It's displaying only Processing

2) I try to use where condition but that also not working.

I tried below code

<table id="list" class="table table-striped table-bordered">
  <thead>
    <tr class="table-column-heading">
      <th>Name</th>
      <th>Email_Id</th>
      <th>Payment id</th>
      <th>Date Of Added</th>
      <th>Action</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>
<script>
  $(document).ready(function() {
    var dataTable = $('#list').DataTable({
      "processing": true,
      "serverSide": true,
      "ajax": {
        url: "fetch.php",
        type: "post",
        //data: {'action': 'servicelist'}
      }
    });
  });
</script>

fetch.php

$table = 'tbl_participantdetails';
$primaryKey = 'pd_id';
$columns = array(
    array( 'db' => 'pd_name', 'dt' => 0 ),
    array( 'db' => 'pd_email',  'dt' => 1 ),
    array( 'db' => 'paid',   'dt' => 2 ),
    array( 'db' => 'payment_id', 'dt' => 3,),
    array( 'db' => 'date_of_added','dt' => 4,
        'formatter' => function( $d, $row ) {
            return date( 'd-m-Y', strtotime($d));
        }
    )
);
require( 'datatables/ssp.class.php' );
$where = "paid =1";

echo json_encode(
    SSP::simple( $_GET, $pdo, $table, $primaryKey, $columns,$where )
);

This is the second option I tried and it's working

<table id="list" class="table table-striped table-bordered">
  <thead>
    <tr class="table-column-heading">
      <th>Name</th>
      <th>Email_Id</th>
      <th>Paid</th>
      <th>Payment id</th>
      <th>Date Of Added</th>
      <th>Action</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>
$(document).ready(function() {
  var dataTable = $('#list').DataTable({
    "processing": true,
    "serverSide": true,
    "paging": true,
    "searchable": true,
    "ajax": {
      url: "fetch.php",
      type: "post"
    },
    language: {
      sLengthMenu: "Show _MENU_", // remove entries text
      searchPlaceholder: "Search",
      emptyTable: "No record found",
      search: ""
    },
    "pageLength": 25,
    "paging": true,
    "columns": [{
        "data": "pd_name"
      },
      {
        "data": "pd_email"
      },
      {
        "data": "paid"
      },
      {
        "data": "payment_id"
      },
      {
        "data": "date_of_added"
      }
    ]
  });
});

fetch.php

$stmt = $pdo->prepare("SELECT count(*) FROM  tbl_participantdetails WHERE is_active = 1 and paid=1");
$stmt->execute();
$totalRecords = $stmt->fetchColumn();
$query="SELECT `pd_id`, `pd_name`, `pd_pic`, `pd_email`, `paid`, `payment_id`, `date_of_added` FROM `tbl_participantdetails` WHERE is_active= 1 and paid=1";
try {
                  $stmt = $pdo->prepare($query);
                  $stmt->execute();
                  $result = $stmt->fetchAll();

              $data['data'] = [];
              foreach ($result as $row) {
        $arr_result = array(
                    //"id" =>$i++,
                    "pd_name" =>"<img src='".$row['pd_pic']."'>'".$row['pd_name'],
                    "pd_email" => $row['pd_email'],
                    "paid" => $row['paid'],
                    "payment_id" => $row['payment_id'],
                    "date_of_added" => $row['date_of_added']
        );


                 $data['data'][] = $arr_result;
                }
                }
                catch(PDOException $e) {
                    echo "Error: " . $e->getMessage();
                }

$json_data = array(
"draw"            => intval($_REQUEST['draw'] ),
"recordsTotal"    => intval($totalRecords ),
"recordsFiltered" => intval($totalRecords),
"data"            => $data['data']
);
echo json_encode($json_data);
exit;
解决方案

Try using SSP::complex() instead of SSP::simple()

And also it should be SSP::complex($_POST...) in PHP, since you are using POST type in your ajax request.

Nothing is wrong with your url properties in the ajax.

这篇关于数据表服务器端处理未在页面上显示输出并且条件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-12 06:42