这是我的模特:
public function count_diabetic(){
$query = $this->db->query("Select count(diabetic) as count_diabetic from member where diabetic is not NULL");
return $query->result_array();
}
public function count_hypertensive(){
$query = $this->db->query("Select count(hypertensive) as count_hypertensive from member where hypertensive is not NULL");
return $query->result();
}
这是我的控制器:
public function home(){
$this->load->model('Jsv_model');
$data = array(
'count_diabetic' => $this->Jsv_model->count_diabetic(),
'count_hypertensive' => $this->Jsv_model->count_hypertensive()
);
$this->session->set_userdata($data);
$this->load->view('home');
}
这是我在php标签中的观点:
echo $this->session->userdata('count_diabetic');
但是这里显示错误,该数组到字符串转换错误.. 请帮帮我
答案 0 :(得分:0)
在PHP中,您可以使用print_r
函数而不是echo
来显示数组。
例如,您必须将代码更改为:
print_r($this->session->userdata['count_diabetic']);
答案 1 :(得分:0)
在count_diabetic()
内,您应该更改$query->result_array()
进入
$query->row()->count_diabetic
,
它只返回计数而不是数组。
也可以count_hypertensive()
。
答案 2 :(得分:0)
你在这一行做错了。
srun
你应该怎么做?
echo $this->session->userdata('count_diabetic');