I am using this codes for my script in search module, I don't know what did I do wrong because last week it is still working. Can anyone help me fix this one?
These images shows the result from echo and print_r to keep track of the data that I am receiving.
this is my "echo $qString;" showing the response from my datepicker
and these 2 images shows the result of the search but it is not displaying on the webpage
here is the whole code for my model and script.
function srch_gen048($data){
$sEcho = intval($data["sEcho"]);
$iDisplayStart = intval($data["iDisplayStart"]); //start of record
$iDisplayLength = intval($data["iDisplayLength"]); //display size
$pageNum = ($iDisplayStart/$iDisplayLength)+1; //page num
$colSort = $data['iSortCol_0'];
$dirSort = strtoupper($data['sSortDir_0']);
$qString = "dbo.SEARCH_gen048 ";
$qString .= "" . $colSort . ",";
$qString .= "'" . $dirSort . "',";
$qString .= "" . $pageNum . ",";
$qString .= "" . $iDisplayLength . ",";
$qString .= "" . $sEcho . ",";
$qString .= "'" . $data['sfDate'] . "'";
//echo $qString;
$this->db->query('set ansi_padding on
set ARITHABORT on
set CONCAT_NULL_YIELDS_NULL on
set QUOTED_IDENTIFIER on
set ANSI_NULLS on
set ANSI_WARNINGS on
set numeric_roundabort off');
$res = $this->db->query($qString);
$res = $res->result();
$iTotalDisplayRecords = 0;
$iTotalRecords = 0;
if(count($res) > 0)
{
$iTotalDisplayRecords = intval($res[0]->TOTAL_ROWS); //used for paging/numbering; same with iTotalRecords except if there will be search filtering
$iTotalRecords = intval($res[0]->TOTAL_ROWS); //total records unfiltered
}
//print_r($res);
$output = array(
"sEcho" => intval($sEcho),
"iTotalRecords" => $iTotalRecords,
"iTotalDisplayRecords" => $iTotalDisplayRecords,
"aaData" => array()
);
if(count($res) > 0)
{
foreach($res as $row)
{
$output['aaData'][] = array(
$row->accnum,
$row->accname,
$row->add1,
$row->accdate,
$row->rmcode,
$row->add4,
$row->solcode,
);
}
}
//print_r($output)
return json_encode( $output );
}
and this is for my script, I think its working properly since the model and controller is the only codes that I've edited since the last time that it is working.
<script>
$(document).ready( function () {
$('#acctable').dataTable({
"sPaginationType": "full_numbers",
"bAutoWidth": false,
"bFilter": false,
"bProcessing": true,
"bLengthChange": false,
"bServerSide": true,
"sAjaxSource": "<?php echo site_url() ?>/welcome/get_gen048",
"sServerMethod": "GET",
"fnServerData": function (sSource, aoData, fnCallback ) {
aoData.push( { "name": "sfDate" , "value": "<?php echo $_POST["sfDate"] ?>" } );
$.getJSON( sSource, aoData, function (json) {
fnCallback(json);
} );
},
"aoColumns": [
{ "sClass": "leftAligned" , "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned" , "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned" , "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned" , "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned" , "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned" , "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned" , "bSortable" : true, "bAutoWidth": false }
]
}); // oTable
} );
</script>
No Need to Convert output
array into json_encode
format.
Try to change few modifications In controller
foreach($res as $row)
{
$data['accnum']=$row->accnum;
$data['accname']=$row->accname;
$data['add1']=$row->add1;
$data['accdate']=$row->accdate;
$output['aaData'][] = $data;
}
return $output;
and in your view script change like this.
mData
property can be used to read data from any JSON data source property
"aoColumns": [
{ "mData": "accnum","sClass": "leftAligned" , "bSortable" : true, "bAutoWidth": false },
{ "mData": "accname","sClass": "leftAligned" , "bSortable" : true, "bAutoWidth": false },
etc..
Thanks !