【发布时间】:2016-11-28 14:36:40
【问题描述】:
我的报告网站上有 2 个页面表现不同。我正在使用 DataTables 服务器端处理。第一页只返回了 74 行(我知道它实际上并不需要使用服务器端处理),而另一页有 30,000 多行和 65 列以上。第一个页面渲染得很好,第二个说它找不到页面。
编辑
页面是如何加载的:
- 调用ReportPage.php
-
includedfile ContentSearchpage.php 计算将返回多少列和多少行。 (不完全确定我仍然需要这部分,但还没有删除它) -
included文件 DBConn.php 包含连接到我的 SQL DB 的所有连接信息 - 仅使用
thead和tfoot创建表,并根据我保存在 SQL DB 中的列表返回的列填写所有<th></th> - DataTables 的初始化如下所示,使用文件 ServerSide.PHP 将数据发送到服务器进行处理
- ServerSide.php 将收集到的信息发送到 FilterSort.class.php,这是服务器上用来处理数据并返回 JSON 字符串的内容
- DataTables jquery 将返回的 JSON 字符串格式化为表格
这就是我初始化页面的方式:
<script type="text/javascript" class="init">
$(document).ready(function ()
{
console.log("Test");
$('#DataTable').DataTable({
initComplete: function () {
this.api().columns().every(function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo($(column.footer()).empty())
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex($(this).val());
column.search(val ? '^' + val + '$' : '', true, false).draw();
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
});
},
"lengthMenu": [[25, 50, 75, 100, 150], [25, 50, 75, 100, 150]],
"ScrollX": true,
"dom": '<"top"Biflp<"clear">>rt<"bottom"ip<"clear">>',
"buttons": [
{extend: 'collection', text: 'Selection', buttons: ['selectAll', 'selectNone']},
{extend: 'collection', text: 'Export', buttons: ['excel', 'csv', 'pdf']}],
"fixedHeader": {header: true, footer: false},
"select": true,
"processing": true,
"serverSide": true,
"ajax": {"url": "ServerSide.php?PageName=<?php echo $Page; ?>"}
});
});
</script>
这就是我开始页面的方式:
<h1>
<?php
echo $HeadingDesc;
if (strpos($_SERVER['PHP_SELF'],"/",1) > 0)
{
echo "<br>Dev Site";
}
?>
</h1>
<?php
//echo "<br>PageName: " . $Page;
//include('ContentPage.php');
//var_dump($Page);
//include ('Selected.php');
//var_dump($Page);
/* if(($Page == 'COEI_OPR' || $Page == 'OSP_OPR' || $Page == 'MaterialTracking' || $Page == 'MaterialReceived' || $Page == 'ApprovedProjects_PrevDay' || $Page == 'ApprovedProjects' || $Page == 'M6Action' || $Page == 'OPR_COEI' || $Page == 'OPR_OSP'))// && !isset($_GET['Project']))
{
require_once 'SearchTerm.php';
//include 'ContentSearchPage.php';
include 'DBConn.php';
}
else
{ */
include 'ContentSearchPage.php';
include 'DBConn.php';
$getHeadings = $conn->query($hsql);
$rHeadings = $getHeadings->fetchALL(PDO::FETCH_ASSOC);
$CountHeadings = count($rHeadings);
//print_r($hsql);
$tsqlHeadings = '';
for ($row = 0; $row < $CountHeadings; $row++)
{
$headings[$row] = $rHeadings[$row]["Headings"];
$tsqlHeadings = $tsqlHeadings."[".$headings[$row].'],';
}
if ($DataTable == 1)
{
$CountTSQL = "Select count(*) ".$tsql;
$tsql = "Select ".substr($tsqlHeadings,0,strlen($tsqlHeadings) - 1).$tsql;
}
else
{
$CountTSQL = "Select count(*) ".$tsql;
$tsql = "Select ".substr($tsqlHeadings,0,strlen($tsqlHeadings) - 1).$tsql." order by Id OFFSET $offset ROWS FETCH NEXT $limit ROWS ONLY";
}
?>
<table id="DataTable" class="display nowrap" style="width: 100%; border: 1px">
<thead>
<tr>
<?php
foreach ($headings as $heading)
{
?>
<th class="cell"><?php echo $heading; ?></th>
<?php
}
?>
</tr>
</thead>
<tfoot>
<tr>
<?php
foreach ($headings as $heading)
{
?>
<th class="cell">
<?php echo $heading; ?>
</th>
<?php
}
?>
</tr>
</tfoot>
</table>
<?php //} ?>
</body>
ContentSearchPage.php:
<?php
case 'MaterialTrackingAll':
try
{
include 'SearchParameters.php';
include 'DBConn.php';
$OneButton = 1;
$Edit = 0;
$SQLArray = array ("searchState" => $searchState,"searchProject" => $searchProject);
$CountSQL = "select count(*) from pmdb.v_MaterialTracking_OPCEN";
$TotalRows = $conn->query($CountSQL)->fetchColumn();
$offset = '';
$currentpage = '';
$DataTable = 1;
$tsql = " FROM pmdb.v_MaterialTracking_OPCEN";
$hsql = "select Headings from TableHeadings where TableName = 'v_MaterialTracking_OPCEN' order by ID";
}
catch (Exception $e)
{
die(print_r($e->getMessage()));
}
break;
case 'QDefs':
try
{
include 'SearchParameters.php';
include 'DBConn.php';
$Edit = 1;
$OneButton = 1;
$SQLArray = array ("searchState" => $searchState,"searchProject" => $searchProject);
$CountSQL = "select count(*) from pmdb.v_QDefs";
$TotalRows = $conn->query($CountSQL)->fetchColumn();
if ($TotalRows > 500)
{
include 'NavButtons.php';
$DataTable = 0;
}
elseif ($TotalRows <= 500)
{
$offset = '';
$currentpage = '';
$DataTable = 1;
}
$tsql = " from pmdb.v_QDefs";
$hsql = "select Headings from TableHeadings where TableName = 'v_QDefs' and Headings != 'Edit' order by Id";
}
catch (Exception $e)
{
die(print_r($e->getMessage()));
}
break;
?>
而文件ServerSide.php只是从here调用ssp.class.php的文件的修改版本,我修改了ssp.class.php 以便它使用 PDO::SQLSRV 而不是 MySql。
我可以很好地运行第一页,表格出现并且可以使用。第二张桌子没有出现。我只得到标题,然后是一条消息:
404 - 找不到文件或目录。 您要查找的资源可能已被删除、名称已更改或暂时不可用。
我不知道是什么问题。
【问题讨论】:
-
我的猜测是您已经复制了第二个文件,因此它的权限不允许 www 用户读取或执行。这可能是,如果您使用本身权限不足的文件阅读器复制文件。
-
@davidkonrad 如果是这样的话,我就不会有任何一个页面的表格。它们都使用相同的文件集。我更新了我的问题,希望能澄清这一点。不同页面之间唯一变化的是
PageName,它被发送到ServerSide.php文件,该文件用作获取返回数据的SQL表名。
标签: php datatables datatables-1.10