Datatables server side not showing data
Datatables server side not showing data
i have a script server side like this...
[code]
$aColumns = array('username', 'level');
$sIndexColumn = "id";
$sTable = "users";
<--------bla-bla-bla---------->
$sQuery = " SELECT SQL_CALC_FOUND_ROWS " . str_replace(" , ", " ", implode(", ", $aColumns)) . "
FROM $sTable
$sWhere
$sOrder
$sLimit
";
$rResult = $this->db->query($sQuery);
/* Data set length after filtering */
$sQuery = " SELECT FOUND_ROWS() ";
$rResultFilterTotal = $this->db->query($sQuery);
$aResultFilterTotal = $rResultFilterTotal->fetch();
$iFilteredTotal = $aResultFilterTotal[0];
$sQuery2 = $this->db->prepare("SELECT COUNT(*) FROM users");
$sQuery2->execute();
if ($row = $sQuery2->fetch(PDO::FETCH_NUM))
$iTotal = $row[0];
$output = array(
"sEcho" => intval(!isset($_GET['sEcho'])),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);
while ($aRow = $rResult->fetch()) {
$row = array();
for ($i = 0; $i < count($aColumns); $i++) {
if ($aColumns[$i] == "version") {
/* Special output formatting for 'version' column */
$row[] = ($aRow[$aColumns[$i]] == "0") ? '-' : $aRow[$aColumns[$i]];
} else if ($aColumns[$i] != ' ') {
/* General output */
$row[] = $aRow[$aColumns[$i]];
}
}
$output['aaData'][] = $row;
}
print json_encode($output);
[/code]
and then output code above like this
[code]
{"sEcho":1,"iTotalRecords":"2","iTotalDisplayRecords":"2","aaData":[["van","1"],["van","0"]]}
[/code]
this my jquery
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://localhost/my_project/user/tes"
} );
});
[/code]
but data not showing..
can help allan..
[code]
$aColumns = array('username', 'level');
$sIndexColumn = "id";
$sTable = "users";
<--------bla-bla-bla---------->
$sQuery = " SELECT SQL_CALC_FOUND_ROWS " . str_replace(" , ", " ", implode(", ", $aColumns)) . "
FROM $sTable
$sWhere
$sOrder
$sLimit
";
$rResult = $this->db->query($sQuery);
/* Data set length after filtering */
$sQuery = " SELECT FOUND_ROWS() ";
$rResultFilterTotal = $this->db->query($sQuery);
$aResultFilterTotal = $rResultFilterTotal->fetch();
$iFilteredTotal = $aResultFilterTotal[0];
$sQuery2 = $this->db->prepare("SELECT COUNT(*) FROM users");
$sQuery2->execute();
if ($row = $sQuery2->fetch(PDO::FETCH_NUM))
$iTotal = $row[0];
$output = array(
"sEcho" => intval(!isset($_GET['sEcho'])),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);
while ($aRow = $rResult->fetch()) {
$row = array();
for ($i = 0; $i < count($aColumns); $i++) {
if ($aColumns[$i] == "version") {
/* Special output formatting for 'version' column */
$row[] = ($aRow[$aColumns[$i]] == "0") ? '-' : $aRow[$aColumns[$i]];
} else if ($aColumns[$i] != ' ') {
/* General output */
$row[] = $aRow[$aColumns[$i]];
}
}
$output['aaData'][] = $row;
}
print json_encode($output);
[/code]
and then output code above like this
[code]
{"sEcho":1,"iTotalRecords":"2","iTotalDisplayRecords":"2","aaData":[["van","1"],["van","0"]]}
[/code]
this my jquery
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://localhost/my_project/user/tes"
} );
});
[/code]
but data not showing..
can help allan..
This discussion has been closed.
Replies
the problem has been found "sEcho" => intval(!isset($_GET['sEcho']))," to be "sEcho" => intval($_GET['sEcho'])",
but new problems arise ..
Notice: Undefined index: sEcho
how to fix it..