如何在Codeigniter中显示模型中的数组返回到视图

时间:2019-01-30 09:08:00

标签: php arrays codeigniter

我的模特:

function get_client() {
$data['latestproblem'] = $this->db->select('hero,client,catprob,action,created_at')->where('client', $client)->order_by('created_at', 'DESC')->limit(1)->get('histprob')->result();
$data['stats'] = $this->db->where('client', $client)->where('catprob', 'HEADSET TIDAK BERFUNGSI')->count_all_results('histprob');
return $data;
}

我的控制器

$this->skejuler_m->get_client();

我的观点:

echo $stats;

我收到错误未定义变量:统计信息

请帮助。

1 个答案:

答案 0 :(得分:1)

尝试返回这样的多个查询结果

$data['latestproblem'] = $this->db->select('hero,client,catprob,action,created_at')->where('client', $client)->order_by('created_at', 'DESC')->limit(1)->get('histprob')->result();
$data['stats'] = $this->db->where('client', $client)->where('catprob', 'HEADSET TIDAK BERFUNGSI')->count_all_results('histprob');
return $data;

在您看来,使用json_decode()来显示数据

foreach(json_decode($latestproblem) as $row){

   echo $row->hero;
   echo $row->client;
}