php - 将 or_where 限制为 codeigniter 中 2 个 where 之间的特定 where

标签 php mysql codeigniter where-clause

我有这个代码:

    $this->db->where('status',1);
    $this->db->where('category',$category_id);
    $this->db->or_where('parent_category',$category_id);
    $this->db->or_where('grandParent_category',$category_id);
    $this->db->or_where('parentOfGP_category',$category_id);
    $query = $this->db->get('posts');

问题是第一个被覆盖的位置,并且由于下一个 or_wheres 而它也得到了具有 0 和 2 状态的位置,而不是我希望 or_wheres 仅适用于 where('category',$category_id);而不是为了地位

有没有办法在 codeigniter 中做到这一点?

最佳答案

您可以直接传入查询,而不是使用 Active Records:

$query = $this->db->query('SELECT name, title, email FROM my_table');

此外,如果您想确定上面的 Active Record 查询到底形成了什么,请使用以下方法:

echo ($this->db->last_query());

关于php - 将 or_where 限制为 codeigniter 中 2 个 where 之间的特定 where,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32679792/

相关文章:

mysql - 使用单个 SQL 连接语句从多个 MySQL 表添加条目,但前提是第二个表中有可用条目

php - 如何解决未捕获的 PDOException "SQLSTATE[HY000] [1045] Access denied for user..."?

javascript - 在 Javascript 中动态添加

php - 一切正常,但显示严重性 : Notice Message: Undefined variable: categories

Git 和 Github 工作流程,使用父级更改更新子树

php: 从 cp1251 转换为 utf8

php - PHP 中的 Xdebug 返回什么?

php - CakePhp 在一个自定义模型中访问多个表

php - 使用 app()->make 创建的模拟类

javascript - 如何将事件分配给由 n 个计数组成的输入和复选框?