2017-06-08 4 views
0

への配列は私のモデルである:ここCodeIgniterの:ここでは、文字列変換エラー

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

あなたは、

$query->row()->count_diabetic

$query->result_array()

を変更する必要があり、それは数を返します配列ではなく数えます。

count_hypertensive()でも行います。

+0

ありがとうございました..それは働いた –

+0

あなたは私の答えを受け入れることができますか? – Ukasyah

0

PHPでは、echoの代わりにprint_r関数を使用して配列を表示できます。

たとえば、あなたがあなたのコードを変更する必要があります。count_diabetic()内部

print_r($this->session->userdata['count_diabetic']); 
0

この行で間違っています。

echo $this->session->userdata('count_diabetic'); 

あなたはどうしたらよいですか?

// To Set a Data in Session 
$session_data = array(
    'count_diabetic' => $this->Jsv_model->count_diabetic(), 
    'count_hypertensive' => $this->Jsv_model->count_hypertensive() 
    );  
$this->session->set_userdata('user_data', $session_data); 

// To get the session data 
$session_data = $this->session->userdata('user_data'); 
$user_name = $session_data['username']; 
$count_diabetic = $session_data['count_diabetic']; 
$count_hypertensive = $session_data['count_hypertensive']; 
関連する問題