Datatables server side not showing data

Datatables server side not showing data

vidihookvidihook Posts: 2Questions: 0Answers: 0
edited May 2013 in General
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..

Replies

  • vidihookvidihook Posts: 2Questions: 0Answers: 0
    owwhhh...

    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..
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Link to a test case please: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read
This discussion has been closed.