2016-11-24 64 views
0

我正在学习codeigniter并做了一个todo应用程序。我做了一个项目列表,当它们被选中时,它们应该在数据库中从0更新到1.这是我的控制器。Codeigniter更新函数更新所有行

public function item_done($id){ 
    $this->db->from('list_items'); 
    $st="item_id='".$id."'"; 
    $this->db->where($st, NULL, FALSE); 
    $q = $this->db->get(); 
    if ($q->num_rows() == 0){ 
     redirect('main/restricted'); 
    } else { 

    $this->db->update('list_items', array('item_done' => '1')); 
      redirect('lists/view_list/'); 
     } 
} 

这是我的数据库 screen http://image.prntscr.com/image/9e739454d14049bc836777754108cd95.png

回答

0

,我发现我的错误,我忘了补充where这是应该的$this->db->where($st, NULL, FALSE)->update('list_items', array('item_done' => '1'));

1

ü也试试这个

  $this->db->where('item_id',$st); 
     $this->db->update('list_items', array('item_done' => '1'));