数据表贴在处理数据,json_encode SQL - PHP

问题描述:

当试图将数据从SQL使用在PHP json_encode数据表,该表只继续显示“正在处理...”数据表贴在处理数据,json_encode SQL - PHP

我的控制台日志显示:

Uncaught TypeError: undefined is not a function highcharts.js:17(anonymous function) highcharts.js:17(anonymous function) highcharts.js:308 XHR finished loading: POST " http://website.com/data.php ". jquery.js:4 Uncaught TypeError: Cannot read property 'length' of undefined jquery.dataTables.js:2673_fnAjaxUpdateDraw jquery.dataTables.js:2673(anonymous function) jquery.dataTables.js:2519baseAjax.success jquery.dataTables.js:2443m.Callbacks.j jquery.js:2m.Callbacks.k.fireWith jquery.js:2x jquery.js:4m.ajaxTransport.send.b jquery.js:4XMLHttpRequest.send (async)m.ajaxTransport.send jquery.js:4m.extend.ajax jquery.js:4_fnBuildAjax jquery.dataTables.js:2495_fnAjaxUpdate jquery.dataTables.js:2515_fnDraw jquery.dataTables.js:1982_fnReDraw jquery.dataTables.js:2101_fnInitialise jquery.dataTables.js:3276(anonymous function) jquery.dataTables.js:6510m.extend.each jquery.js:2m.fn.m.each jquery.js:2DataTable jquery.dataTables.js:6041(anonymous function) datatables:176m.Callbacks.j jquery.js:2m.Callbacks.k.fireWith jquery.js:2m.extend.ready jquery.js:2J jquery.js:2

我的index.php是这样的:

<table id="table_id" class="display"> 
    <thead> 
     <tr> 
      <th>_RowNumber</th> 
      <th>DNumber</th> 
      <th>ItemNumber</th> 
     </tr> 
    </thead> 



</table> 



<script> 
$(document).ready(function() { 
    $('#table_id').dataTable({ 
     "processing": true, 
     "serverSide": true, 
     "ajax": { 
      "url": "<?php echo url(); ?>/new/data.php", 
      "type": "POST" 
     }, 
     "columns": [ 
      { "data": "_RowNumber" }, 
      {"data": "DNumber"}, 
      { "data": "ItemNumber" } 
     ] 
    }); 
}); 
</script> 

和data.php是这样的:

<?php 
$SQL = "SELECT * 
FROM (SELECT Row_number() 
       OVER (
        ORDER BY _sys_id) AS _RowNumber, 
       * 
     FROM (SELECT PList.deliverynumber AS DNumber, 
         PLine.picklistnumber, 
         PLine.picklistsuffix, 
         itemnumber, 
         fromlocation, 
         expectedquantity, 
         pickedquantity, 
         currentlocation, 
         ordernumber, 
         orderline, 
         PLine.complete, 
         PLine.insertdate, 
         itemdescription, 
         PList.complete  AS StatusCode, 
         PList.complete  AS Description, 
         PList.id    AS _SYS_ID 
       FROM picklist PList 
         JOIN pickline PLine 
         ON PList.picklistsuffix = PLine.picklistsuffix 
          AND PList.picklistnumber = PLine.picklistnumber) AS 
       LIST_TABLE 
     WHERE 1 = 1) AS tmp_rows 
WHERE 1 = 1 
     AND _RowNumber BETWEEN 1 AND 10 
     "; 


$Query = $pdo->prepare($SQL); 
$Query->execute(); 
$rows = array(); 
foreach ($pdo->query($SQL) as $row) { 

    $rows[] = $row; 


} 

print json_encode($rows); 
?> 

导航到data.php这样表示当结果:

[{"_RowNumber":"1","0":"1","DNumber":"0800","1":"0800","PickListNumber":"12667","2":"12667","PickListSuffix":"1","3":"1","ItemNumber":"FFT112","4":"FFT112","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12667","9":"12667","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"}, 
{"_RowNumber":"2","0":"2","DNumber":"0999","1":"0999","PickListNumber":"12667","2":"12667","PickListSuffix":"1","3":"1","ItemNumber":"FFT112","4":"FFT112","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12667","9":"12667","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"}, 
{"_RowNumber":"3","0":"3","DNumber":"3333","1":"3333","PickListNumber":"12667","2":"12667","PickListSuffix":"1","3":"1","ItemNumber":"FFT112","4":"FFT112","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12667","9":"12667","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"}, 
{"_RowNumber":"4","0":"4","DNumber":"1221","1":"1221","PickListNumber":"12667","2":"12667","PickListSuffix":"1","3":"1","ItemNumber":"FFT112","4":"FFT112","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12667","9":"12667","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"}, 
{"_RowNumber":"5","0":"5","DNumber":"6665","1":"6665","PickListNumber":"12667","2":"12667","PickListSuffix":"1","3":"1","ItemNumber":"FFT112","4":"FFT112","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12667","9":"12667","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"}, 
{"_RowNumber":"6","0":"6","DNumber":"7764","1":"7764","PickListNumber":"55555","2":"55555","PickListSuffix":"1","3":"1","ItemNumber":"FFT412","4":"FFT412","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12637","9":"12637","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"}, 
{"_RowNumber":"7","0":"7","DNumber":"3322","1":"3322","PickListNumber":"55555","2":"55555","PickListSuffix":"1","3":"1","ItemNumber":"FFT412","4":"FFT412","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12637","9":"12637","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"}, 
{"_RowNumber":"8","0":"8","DNumber":"1221","1":"1221","PickListNumber":"55555","2":"55555","PickListSuffix":"1","3":"1","ItemNumber":"FFT412","4":"FFT412","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12637","9":"12637","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"}, 
{"_RowNumber":"9","0":"9","DNumber":"1997","1":"1997","PickListNumber":"55555","2":"55555","PickListSuffix":"1","3":"1","ItemNumber":"FFT412","4":"FFT412","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12637","9":"12637","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"}, 
{"_RowNumber":"10","0":"10","DNumber":"1696","1":"1696","PickListNumber":"55555","2":"55555","PickListSuffix":"1","3":"1","ItemNumber":"FFT412","4":"FFT412","FromLocation":"LONDON","5":"LONDON","ExpectedQuantity":"1.0","6":"1.0","PickedQuantity":"1.0","7":"1.0","CurrentLocation":"DESPATCH","8":"DESPATCH","OrderNumber":"12637","9":"12637","OrderLine":"1","10":"1","Complete":"1","11":"1","InsertDate":"2014-05-30 16:17:14.000","12":"2014-05-30 16:17:14.000","ItemDescription":"New Today","13":"New Today","StatusCode":"F","14":"F","Description":"F","15":"F","_SYS_ID":"133","16":"133"}] 

我需要做什么来改变数据在数据表表中显示? https://datatables.net/

我发现这个问题,我不得不使用

$rows['aaData'][] 

,而不是仅仅

$rows[] 

在foreach()语句

请参考此链接为您回答。 http://legacy.datatables.net/usage/server-side 只是用sAjaxDataProp配置项进行修复

+0

你或许应该扩大这个回答有点多(也许一个例子吗?),以防止它被标记为唯一的链接的答案(和删除)。 – Carpetsmoker 2014-12-13 03:04:28

如果同时使用背景页,也许你可以解决这个问题是这样的:当您返回到的寻呼信息的数据结构,可以重置返回sEcho为0,这样的:例如:

dataSource.setsEcho(0);//I try set 0,It's work for me,you can try 
dataSource.setAaData(tempList); 
dataSource.setiTotalDisplayRecords(totalNum); 
dataSource.setiTotalRecords(totalNum);