Codeigniter model with multiple update conditions using manual where statement

廉价感情. 提交于 2019-12-02 01:23:00

问题


I have this code in model that returns data

$this->db->select('title, content, date');

$where = "name='Joe' AND status='boss'";

$this->db->where($where);

$query = $this->db->get('mytable');

return $query->result();

I am using a manual where and i wanted to know whether the concept of manual where in updates and possibly in deletes is allowed.

This code updates a table based on a single where condition

$data = array(
               'title' => $title,
               'name' => $name,
               'date' => $date
             );

$this->db->where('id', $id);
$this->db->update('mytable', $data);

Is doing this allowed in codeigniter

$data = array(
               'title' => $title,
               'name' => $name,
               'date' => $date
             );

$where = "id=$id, name='Joe' AND status='boss'";

$this->db->where($where);

$this->db->update('mytable', $data);

回答1:


As per document in CodeIgniter Where, you have to mention here with OR or AND "id=$id, name='Joe'.

$where = "id=$id AND/OR name='Joe' AND status='boss'";
                  ^^^^
                Chose one


Or use array



来源:https://stackoverflow.com/questions/45709112/codeigniter-model-with-multiple-update-conditions-using-manual-where-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!