2016-03-30 63 views
0

更新多個行我有一個名爲employee_tbl表看起來像這樣:使用代碼點火器符合條件

The table looks like this :

我使用的代碼點火器爲這個項目。

型號:

public function update(){ 

    $data = array(
     'floor' => 'First' 
    ); 

    $this->db->where('type', 'Cleaner');  

    if($this->db->update('employee_tbl',$data)) { 
     return true; 
    } 
    else{ 
     return false; 
    }    
} 

我發現很難解決這個問題,任何幫助,將不勝感激。

回答

0

您也可以使用這樣的:在docs

0

$data = array(
    'floor' => 'First' 
); 
$this->db->update('employee_tbl', $data, array('type' => 'Cleaner')); 
// or 
// $this->db->update('employee_tbl', $data, 'type = "Cleaner"'); 

更多信息你可以做很多的方式。 這裏是其中的一個

$this->db->where('type','Cleaner'); 
$this->db->set('floor', 'First'); 
$this->db->update('employee_tbl'); 

瞭解更多從CI docs

0

首先設置你的數據:

$this->db->set('column_name', $column_vale); 

然後確定要更新:

$this->db->where('type','cleaner'); //produces where type = 'cleaner' 

最後更新表

$this->db->update('table_name');