DataTable服务器端仅在我有几个数据时才起作用 [英] DataTable server side works only when I have a few data

查看:95
本文介绍了DataTable服务器端仅在我有几个数据时才起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从json加载到服务器端处理关于我的Datatable的表。我有两个环境,一个用于测试和生产。它们具有相同的特征和数据库结构。当我在测试环境中测试新的进程时,脚本加载数据没有任何问题(5行)。



相同的脚本不会在生产环境中加载数据(1200行)。该行出了什么问题?

  $ sql。=ORDER BY。 $ columns [$ requestData ['order'] [0] ['column']]。。$ requestData ['order'] [0] ['dir']。LIMIT$ requestData ['start'] 。,$ requestData ['length']。; 

/ var / log / httpd / error_log

  [Wed Oct 19 14:55:37.724942 2016] [:error] [pid 28440] [client xxxxxx] PHP注意:未定义的索引:在search_user中。 php on line 31,referer:search_user.php 
[Wed Oct 19 14:55:37.724958 2016] [:error] [pid 28440] [client xxxxxx] PHP注意:未定义的索引:在search_user.php中的顺序31,referer:search_user.php
[Wed Oct 19 14:55:37.724971 2016] [:error] [pid 28440] [client xxxxxx] PHP注意:未定义的索引:在第31行的search_user.php中开始,引用:search_user.php
[Wed Oct 19 14:55:37.724983 2016] [:error] [pid 28440] [client xxxxxx] PHP注意:未定义的索引:第31行中search_user.php的长度,引用者:search_user。 php

PHP

 <?php 
requirecommon.php;
$ requestData = $ _REQUEST;
$ columns = array(
0 =>'id',
1 =>'email',
2 =>'nome',
3 =>'cognome',
4 =>'lingua',
5 =>'unsubscribe'
);
$ sql =SELECT id,email,nome,cognome,lingua,unsubscribe FROM newsletter_utenti;
$ query = mysqli_query($ db,$ sql)或die();
$ totalData = mysqli_num_rows($ query);
$ totalFiltered = $ totalData;

$ sql =SELECT id,email,nome,cognome,lingua,unsubscribe;
$ sql。=FROM newsletter_utenti WHERE 1 = 1;
if(!empty($ requestData ['search'] ['value'])){
$ sql。=AND(id LIKE'。$ requestData ['search'] ['value '。%';
$ sql。=OR email LIKE'$ requestData ['search'] ['value']。%;
$ sql。= ORACLE LIKE'$ requestData ['search'] ['value']。 ]%';
$ sql。=OR lingua LIKE$ requestData ['search'] ['value']。%');
}
$ query = mysqli_query($ db,$ sql)或die(test);
$ totalFiltered = mysqli_num_rows($ query);
$ sql。=ORDER BY。 $ columns [$ requestData ['order'] [0] ['column']]。。$ requestData ['order'] [0] ['dir']。LIMIT$ requestData ['start'] 。,$ requestData ['length']。;
//$sql.=ORDER BY id desc LIMIT 0,30;
$ query = mysqli_query($ db,$ sql)或死(errore order by);

$ data = array();
while($ row = mysqli_fetch_array($ query)){
$ nestedData = array();
$ nestedData [] = $ row [id];
$ nestedData [] = $ row [email];
$ nestedData [] = $ row [nome];
$ nestedData [] = $ row [cognome];
$ nestedData [] = $ row [lingua];
$ nestedData [] = $ row [unsubscribe];
$ data [] = $ nestedData;
}
$ json_data = array(
draw=> intval($ requestData ['draw']),
recordsTotal=> intval($ totalData) ,
recordsFiltered=> intval($ totalFiltered),
data=> $ data
);

echo json_encode($ json_data);
?>


解决方案

解决!



MySQL实例未配置为默认从客户端连接预期UTF-8编码,因此我使用 SET NAMES utf8



谢谢大家! :)


I'm passing from json loading to server side processing about my Datatable's table. I have two environments, one for tests and the prodution. They have same features and database structure. When i test the new process in the test environment, the script loads data without any problem (5 rows).

The same script doesn't load data in the production environment (1200 rows). What's wrong with that line?

$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";

/var/log/httpd/error_log

[Wed Oct 19 14:55:37.724942 2016] [:error] [pid 28440] [client xxxxxx] PHP Notice:  Undefined index:  in search_user.php on line 31, referer: search_user.php
[Wed Oct 19 14:55:37.724958 2016] [:error] [pid 28440] [client xxxxxx] PHP Notice:  Undefined index: order in search_user.php on line 31, referer: search_user.php
[Wed Oct 19 14:55:37.724971 2016] [:error] [pid 28440] [client xxxxxx] PHP Notice:  Undefined index: start in search_user.php on line 31, referer: search_user.php
[Wed Oct 19 14:55:37.724983 2016] [:error] [pid 28440] [client xxxxxx] PHP Notice:  Undefined index: length in search_user.php on line 31, referer: search_user.php

PHP

<?php
require "common.php" ;
$requestData= $_REQUEST;
$columns = array(
    0 =>'id',
    1 =>'email',
    2 =>'nome',
    3 =>'cognome',
    4 =>'lingua',
    5 =>'unsubscribe'
);
$sql = "SELECT id,email,nome,cognome,lingua,unsubscribe FROM newsletter_utenti";
$query=mysqli_query($db, $sql) or die();
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;

$sql = "SELECT id,email,nome,cognome,lingua,unsubscribe ";
$sql.=" FROM newsletter_utenti WHERE 1=1";
if( !empty($requestData['search']['value']) ) {
    $sql.=" AND ( id LIKE '".$requestData['search']['value']."%' ";
    $sql.=" OR email LIKE '".$requestData['search']['value']."%' ";
    $sql.=" OR nome LIKE '".$requestData['search']['value']."%' ";
    $sql.=" OR cognome LIKE '".$requestData['search']['value']."%' ";
    $sql.=" OR lingua LIKE '".$requestData['search']['value']."%' )";
}
$query=mysqli_query($db, $sql) or die("test");
$totalFiltered = mysqli_num_rows($query);
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";
//$sql.=" ORDER BY id desc LIMIT 0,30   ";
$query=mysqli_query($db, $sql) or die("errore order by");

$data = array();
while( $row=mysqli_fetch_array($query) ) {
    $nestedData=array();
    $nestedData[] = $row["id"];
    $nestedData[] = $row["email"];
    $nestedData[] = $row["nome"];
    $nestedData[] = $row["cognome"];
    $nestedData[] = $row["lingua"];
    $nestedData[] = $row["unsubscribe"];
    $data[] = $nestedData;
}
$json_data = array(
    "draw"            => intval( $requestData['draw'] ),
    "recordsTotal"    => intval( $totalData ),
    "recordsFiltered" => intval( $totalFiltered ),
    "data"            => $data
);

echo json_encode($json_data);
?>

解决方案

Solved!

The MySQL instance is not configured to expect UTF-8 encoding by default from client connections, so I used SET NAMES utf8.

Thank you all! :)

这篇关于DataTable服务器端仅在我有几个数据时才起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆