Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php datatable:为每个列生成服务器端脚本_Php_Mysql_Datatable_Filter_Server Side - Fatal编程技术网

Php datatable:为每个列生成服务器端脚本

Php datatable:为每个列生成服务器端脚本,php,mysql,datatable,filter,server-side,Php,Mysql,Datatable,Filter,Server Side,我想让我的表可以在每一列中进行过滤。我从中获取客户端脚本。为了使这项工作正常,我必须在服务器端对这个datatable脚本进行更改。我的表格字段是:行、型号名称、版本、批次、序列号、ID号、批次号、序列号和生产日期 我曾尝试将每个列同步到此服务器脚本,但总是出现错误。 此脚本包含以下脚本: sSearch: bEscapeRegex:true sSearch_0: bEscapeRegex_0:true bSearchable_0:true sSearch_1: bEscapeRegex_1:t

我想让我的表可以在每一列中进行过滤。我从中获取客户端脚本。为了使这项工作正常,我必须在服务器端对这个datatable脚本进行更改。我的表格字段是:行、型号名称、版本、批次、序列号、ID号、批次号、序列号和生产日期

我曾尝试将每个列同步到此服务器脚本,但总是出现错误。 此脚本包含以下脚本:

sSearch:
bEscapeRegex:true
sSearch_0:
bEscapeRegex_0:true
bSearchable_0:true
sSearch_1:
bEscapeRegex_1:true
bSearchable_1:true
sSearch_2:
bEscapeRegex_2:true
bSearchable_2:true   //data array same until sSearch_7

编辑

这就是查询:

$sWhere = "";
if (postVar('sSearch') !="" )
{
  $sWhere = " WHERE Line LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%'  ";
}
if (postVar('sSearch_0') !="")
{
  $sWhere = " AND Line LIKE '".mysql_real_escape_string( $_POST['sSearch_0'])."' ";
}
if (postVar('sSearch_1') !="") 
{ 
  $sWhere = " AND Model_name LIKE '%".mysql_real_escape_string( $_POST['sSearch_1'])."%' ";
//直到7号研究室

我在该查询中遇到错误:

错误:“查询执行期间发生错误:():您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册,以了解按型号_名称使用“近”和“2”顺序的正确语法 描述限值0,第1行10'


其中*LIKE
不正确

您需要提供一个有效的列名来代替
*

PHP语法错误是因为:

$sWhere = " AND Line LIKE '%".mysql_real_escape_string( $_POST['sSearch_0']."%' ";

缺少
要关闭
mysql\u real\u escape\u string函数
cal

您的代码有几个错误:

  • 我怀疑“*LIKE”是有效的SQL语法。您应该在这里定义一个字段名。如果postVar('sSearch')等于“”,则也无法将“WHERE”添加到查询中

    if (postVar('sSearch') !="" )
    {
             $sWhere = " WHERE * LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%'  ";
    }
    
  • 在mysql_real_escape_string(


  • 您必须将查询链接起来。
    当您将$sWhere替换为其他条件时。
    您可以使用串联(
    =而不是=
    ),但我建议您使用数组:

    $aWhere = array();
    if (postVar('sSearch')) {
      $aWhere[] = "Line LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%'";
    }
    if (postVar('sSearch_0'))
    {
      $aWhere[] = "Line LIKE '".mysql_real_escape_string($_POST['sSearch_0'])."'";
    }
    if (postVar('sSearch_1')) 
    { 
      $aWhere = "Model_name LIKE '%".mysql_real_escape_string( $_POST['sSearch_1'])."%'";
    }
    //and so on
    if (count($aWhere)) $where="WHERE ".implode(' AND ',$aWhere);
    $query="select * from table $where";
    mysql_query($query) or trigger_error(mysql_error().": ".$query);
    

    此代码的最后一行不仅会打印错误消息,还会查询自身,这将非常有帮助

    我是否必须提及所有字段?否..这不起作用..您必须为一个like子句指定一个列名。好的..数据可以显示,但不能过滤数据。并显示错误:near'和line like'2'按型号\名称desc LIMI排序T 0,1号线处的10“
    $aWhere = array();
    if (postVar('sSearch')) {
      $aWhere[] = "Line LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%'";
    }
    if (postVar('sSearch_0'))
    {
      $aWhere[] = "Line LIKE '".mysql_real_escape_string($_POST['sSearch_0'])."'";
    }
    if (postVar('sSearch_1')) 
    { 
      $aWhere = "Model_name LIKE '%".mysql_real_escape_string( $_POST['sSearch_1'])."%'";
    }
    //and so on
    if (count($aWhere)) $where="WHERE ".implode(' AND ',$aWhere);
    $query="select * from table $where";
    mysql_query($query) or trigger_error(mysql_error().": ".$query);