txkj740 发表于 2011-9-24 12:00:13

新手求教:CI里面where的OR判断怎么写?

$this->db->where('cityid', 'beijing');
这一句,现在我是需要cityid = beijing or cityid = xiamen

请问该如何写呢?感谢

Hex 发表于 2016-12-14 15:42:23

yanchunxia 发表于 2016-12-14 12:02
where type='city' and (cityid='beijing' or cityid='xiamen')想要得到这种结果ci框架应该怎么写 ...

QueryBuilder 不是万能的,建议复杂 SQL 直接用 query()

yanchunxia 发表于 2016-12-14 12:02:11

where type='city' and (cityid='beijing' or cityid='xiamen')想要得到这种结果ci框架应该怎么写

zhouli520 发表于 2011-9-24 12:51:11

$this->db->or_where();

~夜行侠~ 发表于 2011-9-24 14:31:31

1.自定义字符串:
$where =”cityid = ‘beijing’ OR cityid = 'xiamen'“;

$this->db->where($where);
或:
2.使用or_where
$this->db->where('cityid ', 'beijing');
$this->db->or_where('cityid', 'xiamen');

dde333 发表于 2011-9-24 19:24:05

感谢楼上,试试!

蓝条 发表于 2011-11-30 11:07:30

mark.

乌有 发表于 2011-12-2 14:44:25

$this->db->where('cityid ', 'beijing');
$this->db->or_where('cityid', 'xiamen');

只是这两个条件的话,没有问题.但如果加多了一个and的条件,这种写法就不行了,如

$this->db->where('type', 'city');
$this->db->where('cityid ', 'beijing');
$this->db->or_where('cityid', 'xiamen');

这样构成的sql语句是
where type='city' and cityid='beijing' or cityid='xiamen'
和下面的结果是不一样的
where type='city' and (cityid='beijing' or cityid='xiamen')

iserich 发表于 2011-12-2 14:46:03

看手册啊。。看手册。

meditator 发表于 2011-12-5 23:49:32

我觉得直接写sql语句方便啊,大家说说呢?还有那个table类也是这样,我直接写table表格,如果配合jquery,那就更方便了。

只想、静一静 发表于 2012-4-10 14:58:15

乌有 发表于 2011-12-2 14:44 static/image/common/back.gif
$this->db->where('cityid ', 'beijing');
$this->db->or_where('cityid', 'xiamen');



那遇到这种写法 怎么办呢?

bingdong700 发表于 2013-7-18 11:36:52

本帖最后由 bingdong700 于 2013-7-18 12:24 编辑

只想、静一静 发表于 2012-4-10 14:58 static/image/common/back.gif
那遇到这种写法 怎么办呢?

[*]查看手册,$this->db->where();里面第四段文字
[*]
[*]
[*]自定义字符串:你可以手动的编写子句:$where = "name='Joe' AND status='boss' OR status='active'";$this->db->where($where);
[*]

页: [1] 2
查看完整版本: 新手求教:CI里面where的OR判断怎么写?