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

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

问题描述

我想在CI中组合AND OR或mysql查询。我已经看过这个主题: http://codeigniter.com/forums/viewthread/92818/
但是它们不能提供确切的解决方案。



如何使用严格的CI框架创建以下查询? (我可以很容易地创建查询没有括号,但是它不是相同的查询。)

  WHERE 
LastName ='Svendson'AND Age =12AND
(FirstName ='Tove'OR FirstName ='Ola'OR Gender =MOR Country =India)

PS:这只是一个示例查询,即使它没有意义,不要建议将整个OR部分写入单个 where()



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

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


解决方案<


$ b

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


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.

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.: 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().

EDIT: Basically I want the implementation of the following simple query:

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

解决方案

and this will work?

$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和OR查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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