我的报告网站上有两页表现不一样。我正在使用DataTables服务器端处理。第一页只返回了74行(我知道它确实不需要使用服务器端处理)而另一页有超过30,000多行,有65列以上。第一页渲染得很好,第二页说它无法找到页面。
修改
如何加载页面:
included
file ContentSearchpage.php 计算将返回的列数和行数。 (不完全确定我仍然需要这部分,但是还没有删除它)included
file DBConn.php 包含连接到我的SQL DB的所有连接信息thead
和tfoot
创建表格,根据我保留在SQL DB中的列表返回的列填写所有<th></th>
这就是我初始化网页的方式:
<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 - 找不到文件或目录。 您要查找的资源可能已被删除,名称已更改或暂时不可用。
我不知道问题所在。
答案 0 :(得分:0)
我已经弄明白了。
我通过$_GET
发送了所有内容。我发送的内容超出了限制,所以它会失败。我改变了它的发送方式,现在使用$_POST
,所以发送数据。这些表现在正在呈现。
"ajax" : {
"url" : "./ServerSide.php",
"type": "POST"
}