简体   繁体   English

具有多个更新条件的Codeigniter模型使用manual where语句

[英]Codeigniter model with multiple update conditions using manual where statement

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. 我正在使用手册where我想知道手册的概念是否允许更新和可能删除。

This code updates a table based on a single where condition 此代码基于单个where条件更新表

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

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

Is doing this allowed in codeigniter 在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);

As per document in CodeIgniter Where , you have to mention here with OR or AND "id=$id, name='Joe' . 根据CodeIgniter 中的文档Where ,你必须在这里提到ORAND "id=$id, name='Joe'

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

在此输入图像描述


Or use array 或者使用数组

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM