2017-08-09 43 views
0

我想使用CodeIgniter在數據庫中更新數據!但我有一個問題Codeigniter foreach未定義的變量更新數據在

查看

<?php foreach ($single_user as $user): ?> 

控制器

$id = $this->uri->segment(3); 
    $data['user'] = $this->authentication->show_students(); 
    $data['single_user'] = $this->authentication->show_student_id($id); 

圖書館

function show_students(){ 
    $query = $this->ci->db->get('users'); 
    $query_result = $query->result(); 
    return $query_result; 
} 
function show_student_id($data){ 
    $this->ci->db->select('*'); 
    $this->ci->db->from('users'); 
    $this->ci->db->where('id', $data); 
    $query = $this->ci->db->get(); 
    $result = $query->result(); 
    return $result; 
} 
+0

您是否加載了認證庫? –

+1

你能描述一下實際的問題嗎? –

+0

I load public function __construct() parent :: __ construct(); $ this-> load-> helper(array('form','url')); $ this-> load-> library('authentication'); } – deadd1wer

回答

0

嘗試添加在你的控制器此表達

$this->load->view('your_view', $data); 

你的代碼必須是這樣的:

$id = $this->uri->segment(3); 
$data['user'] = $this->authentication->show_students(); 
$data['single_user'] = $this->authentication->show_student_id($id); 
$this->load->view('your_view', $data); 

希望它可以幫助你。