我在搜索模块中使用此代码作为我的脚本,我不知道我做错了什么,因为上周它还在运行。任何人都可以帮我解决这个问题吗?
这些图像显示echo和print_r的结果,以跟踪我收到的数据。
这是我的“echo $ qString;”显示我的datepicker的回复
这是我的模型和脚本的完整代码。
$session->login($login['username'], $login['password']);
这是我的脚本,我认为它的工作正常,因为模型和控制器是我上次编辑以来编辑的唯一代码。
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 );
}
答案 0 :(得分:1)
无需将output
数组转换为json_encode
格式。
尝试在控制器中更改一些修改
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;
并在您的视图中脚本更改为。
mData
属性可用于从任何JSON数据源属性中读取数据
"aoColumns": [
{ "mData": "accnum","sClass": "leftAligned" , "bSortable" : true, "bAutoWidth": false },
{ "mData": "accname","sClass": "leftAligned" , "bSortable" : true, "bAutoWidth": false },
etc..
谢谢!