2013-03-25 26 views
-1

任何人都可以幫助我在Codeigniter中更新嗎?Codeigniter for Beginner中的更新

這是我的模型代碼:

function update($data,$userid) 
{ 
    $data = array(
       'dob' => $dob, 
       'sex' => $sex,    
    ); 

    $this->db->where('user_id', $userid); 
    $this->db->update('profile', $data); 
} 
+1

請告訴我問題嗎? – 2013-03-25 17:59:19

+0

這個 – user1912035 2013-03-25 18:05:59

+0

的控制器看起來是對的,假設$ dob和$ sex被填充。你用$ this-> input-> post()獲取它們,還是在$ data數組中,在這種情況下,你需要用$ data ['dob']和$ data ['sex'] – 2013-03-25 18:07:19

回答

0
$where = array('id'=>'10','email'=>'[email protected]'); 
$data = array('username'=>'lol'); 

function update($data,$where){ 
    foreach($where as $key=>$value){ 
     $this->db->where($key,$value); 
    } 
    $this->db->update('users',$data); 
} 
1

假設你通過數據變量傳遞DOB和性別的功能,你只是試圖訪問不正確的。

function update($data,$userid) 
{ 
    $data = array(
       'dob' => $data['dob'], 
       'sex' => $data['sex'],    
    ); 

    $this->db->where('user_id', $userid); 
    $this->db->update('profile', $data); 
} 

對於這個問題,如果這是所有在這一數據變量,您可以完全失去了第一部分,因爲它實際上只是複製你已經擁有。

function update($data,$userid) 
{ 
    $this->db->where('user_id', $userid); 
    $this->db->update('profile', $data); 
}