【问题标题】:Codeigniter update functions updates all rowsCodeigniter 更新函数更新所有行
【发布时间】:2016-11-24 17:03:21
【问题描述】:

我正在学习 codeigniter 并做了一个 todo 应用程序。我列出了一个项目列表,检查后它们应该在数据库中从 0 更新到 1。这是我的控制器。

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/');
        }
}

这是我的数据库

【问题讨论】:

    标签: codeigniter codeigniter-2 codeigniter-3


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      你也试试这个

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

      【讨论】:

        猜你喜欢
        • 2016-09-29
        • 2015-11-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-11
        • 1970-01-01
        • 2015-07-09
        相关资源
        最近更新 更多