在 Codeigniter 中结合 mysql AND OR 查询 [英] combining mysql AND OR queries in Codeigniter

查看:35
本文介绍了在 Codeigniter 中结合 mysql AND OR 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 CI 中结合 AND OR mysql 查询.我已经看过这个帖子:http://codeigniter.com/forums/viewthread/92818/.但他们没有在那里提供确切的解决方案.

I want to combine AND OR mysql queries in CI. I have already seen this thread: http://codeigniter.com/forums/viewthread/92818/. But they don't provide the exact solution there.

我如何严格使用 CI 框架创建以下查询?(我可以在没有括号的情况下轻松创建查询,但它不是同一个查询.)

How do I create the following query using strictly the CI framework? (I can create the query easily without the brackets but then it is not the same query.)

SELECT * FROM `Persons` WHERE
LastName='Svendson' AND Age="12" AND
(FirstName='Tove' OR FirstName='Ola' OR Gender="M" OR Country="India") 

P.S.:这只是一个示例查询,即使它毫无意义&不建议在单个 where() 中编写查询的整个 OR 部分.

P.S.: This is just a sample query even if it makes no sense & Do not suggest writing the entire OR part of the query inside a single where().

基本上我想要实现以下简单查询:

Basically I want the implementation of the following simple query:

SELECT * FROM `table` WHERE field1='value1' AND (field2='value2' OR field3='value3') 

推荐答案

这行得通吗?

$this->db->where('LastName', 'Svendson');
$this->db->where('Age', 12);
$this->db->where("(FirstName='Tove' OR FirstName='Ola' OR Gender='M' OR Country='India')", NULL, FALSE);
$query = $this->db->get('Persons');
return $query->result();

这篇关于在 Codeigniter 中结合 mysql AND OR 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆