我有这个代码:
$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/