手动where语句的具有多个更新条件的Codeigniter模型

手动where语句的具有多个更新条件的Codeigniter模型

本文介绍了使用手动where语句的具有多个更新条件的Codeigniter模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在返回数据的模型中有这段代码

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();

我正在使用手册where,我想知道是否允许在更新甚至删除中使用手册的概念.

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

$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);

推荐答案

根据CodeIgniter中的文档中,您必须在此处用ORAND "id=$id, name='Joe'提及.

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

或使用数组

这篇关于使用手动where语句的具有多个更新条件的Codeigniter模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 03:59