problem show data inside of datatable
problem show data inside of datatable
hi all..
i have a problem to show data inside datatable..after initialize the datatable, still empty althought at firebug show the result and also not show error message..i'm using this code at process page:
[code]
$rResultTotal = mysql_query( $sQuery) or _doError(_ERROR30 . ' (' . htmlspecialchars($sql) . '): ' . mysql_error() ); // submit SQL to MySQL an$
$aResultTotal = mysql_fetch_array($rResultTotal);
$iTotal = $aResultTotal[0];
$sOutput = '{';
$sOutput .= '"sEcho": '.intval($_POST['sEcho']).', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ ';
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$sOutput .= "[";
$sOutput .= '"'.addslashes($aRow['Line']).'",';
$sOutput .= '"'.addslashes($aRow['Model']).'",';
$sOutput .= '"'.addslashes($aRow['Serial_number']).'",';
$sOutput .= '"'.addslashes($aRow['NIK']).'",';
if ( $aRow['Line'] == "0" )
$sOutput .= '"-",';
else
$sOutput .= '"'.addslashes($aRow['Model']).'",';
$sOutput .= '"'.addslashes($aRow['Serial_number']).'"';
$sOutput .= "],";
}
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= '] }';
echo $sOutput;
[/code]
i have a problem to show data inside datatable..after initialize the datatable, still empty althought at firebug show the result and also not show error message..i'm using this code at process page:
[code]
$rResultTotal = mysql_query( $sQuery) or _doError(_ERROR30 . ' (' . htmlspecialchars($sql) . '): ' . mysql_error() ); // submit SQL to MySQL an$
$aResultTotal = mysql_fetch_array($rResultTotal);
$iTotal = $aResultTotal[0];
$sOutput = '{';
$sOutput .= '"sEcho": '.intval($_POST['sEcho']).', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ ';
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$sOutput .= "[";
$sOutput .= '"'.addslashes($aRow['Line']).'",';
$sOutput .= '"'.addslashes($aRow['Model']).'",';
$sOutput .= '"'.addslashes($aRow['Serial_number']).'",';
$sOutput .= '"'.addslashes($aRow['NIK']).'",';
if ( $aRow['Line'] == "0" )
$sOutput .= '"-",';
else
$sOutput .= '"'.addslashes($aRow['Model']).'",';
$sOutput .= '"'.addslashes($aRow['Serial_number']).'"';
$sOutput .= "],";
}
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= '] }';
echo $sOutput;
[/code]
This discussion has been closed.
Replies
Your problem probably is in empty result of qurey to server.
If server trying to return empty data the while cycle is not working
properly and returning array looks like
[code]
{"sEcho": '0', "iTotalRecords": '100', "iTotalDisplayRecords": '0', "aaData": ]}"
[/code]
but it must look (even it's empty) like this:
[code]
{"sEcho": '0', "iTotalRecords": '100', "iTotalDisplayRecords": '0', "aaData":[ ]}"
[/code]
try this:
[code]
$sOutput = '{';
$sOutput .= '"sEcho": '.intval($_POST['sEcho']).', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ ';
if ($iFilteredTotal != 0){
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$sOutput .= "[";
$sOutput .= '"'.addslashes($aRow['Line']).'",';
$sOutput .= '"'.addslashes($aRow['Model']).'",';
$sOutput .= '"'.addslashes($aRow['Serial_number']).'",';
$sOutput .= '"'.addslashes($aRow['NIK']).'",';
if ( $aRow['Line'] == "0" )
$sOutput .= '"-",';
else
$sOutput .= '"'.addslashes($aRow['Model']).'",';
$sOutput .= '"'.addslashes($aRow['Serial_number']).'"';
$sOutput .= "],";
}
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= '] }';
}
else {
$sOutput .= "]}";
}
echo $sOutput;
[/code]
Maybe thereis another problem. Try to check the search input
on empty data and change WHERE condition in query string, like this:
[code]
$sWhere = "";
if ( $_GET['sSearch'] != "" )
{
$sWhere = "WHERE fio LIKE '%".str_replace('"', '\"', $_GET['sSearch'])."%' OR office LIKE '%".str_replace('"', '\"', $_GET['sSearch'])."%' OR n_o LIKE '%".str_replace('"', '\"', $_GET['sSearch'])."%' OR n_m LIKE '%".str_replace('"', '\"', $_GET['sSearch'])."%' ";
}
else
{
$sWhere = "WHERE id <> '0' ";
}
[/code]
It may help.
Good luck. :-)