我想要最后五个实时数据,它工作正常但突然停止,无法弄清楚问题,让我告诉你我在cron中运行3个脚本来更新服务器(LAN)中的数据,Datatable版本 - 1.10.13,有数百万的数据,但只使用最后五个。
表字段包括created_at
的索引。
问题在于,数据表中的数据几乎没有变化,然后没有任何反应。
<table id="dataTables-example" class="table table-striped example">
<thead>
<tr>
<th>Number</th>
<th>TVC Name</th>
<th>License Plate</th>
<th>Date</th>
<th>Time</th>
<th>Action</th>
</tr>
</thead>
</table>
上面的Html,遵循jQuery:
var table = $('#dataTables-example').DataTable({
"aaSorting": [],
ajax: "./licenseData.php",
"bLengthChange": false,
"bFilter": false,
"bPaginate": false,
"columns": [
{ mData: 'slno' } ,
{ mData: 'camera' } ,
{ mData: 'license' },
{ mData: 'dateNewFormat' },
{ mData: 'timeData' },
{ mData: 'actions' }
]
});
setInterval( function () {
table.ajax.reload();
}, 1000 );
以下PHP代码:
public function realtimeLicenseDetails()
{
$i=1;
$r=array();
$stmt=$this->_db->prepare('SELECT cameraName as camera,licensePlate as licensePlate,dateAdded as dateAddedOn,extra as extraData, fileName as fileName FROM license ORDER BY created_at DESC LIMIT 5');
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
while ($row = $stmt->fetch())
{
//set camera for json output
$rData['slno']=$i++;
$rData['camera']=$row['camera'];
//set license for json output
$rData['license']=$row['licensePlate'];
//set date for json output
$dateAdded = $row['dateAddedOn'];
$dateArray = explode("-", $dateAdded);
$dateNewFormat = $dateArray[2].'-'.$dateArray[1].'-'.$dateArray[0];
$rData['dateNewFormat']=$dateNewFormat;
//set time for json output
$timeData = $row['extraData'];
$hours = substr($timeData, 0,2);
$mins = substr($timeData, 2,2);
$secs = substr($timeData, 4,2);
$extraDetails = substr($timeData, 6,3);
$timeDetails = $hours.':'.$mins.':'.$secs.' '.$extraDetails;
$rData['timeData']=$timeDetails;
//set action html buttons for json output
$rData['actions']= '<a class="btn btn-danger" href="/FTPSERVERDEV/images/processed/'.$row['fileName'].'" download="'.$row['fileName'].'"><i class="fa fa-download"></i></a><button type="button" class="show-picture btn btn-danger btn-circle pull-right" title="Show picture" onClick="showPicture(this)" data-img="'.$row['fileName'].'"><i class="fa fa-info"></i></button>';
$r[]=$rData;
}
$results = array(
"sEcho" => 1,
"iTotalRecords" => count($r),
"iTotalDisplayRecords" => count($r),
"aaData" => $r
);
echo json_encode($results);
}
我在licenseData.php中调用它,如下所示:
require 'includes/config.php';
$fileManager->realtimeLicenseDetails();
config只包含对象创建代码和其他不必要的细节。