新手求教:CI里面where的OR判断怎么写?
$this->db->where('cityid', 'beijing');这一句,现在我是需要cityid = beijing or cityid = xiamen
请问该如何写呢?感谢 yanchunxia 发表于 2016-12-14 12:02
where type='city' and (cityid='beijing' or cityid='xiamen')想要得到这种结果ci框架应该怎么写 ...
QueryBuilder 不是万能的,建议复杂 SQL 直接用 query() where type='city' and (cityid='beijing' or cityid='xiamen')想要得到这种结果ci框架应该怎么写 $this->db->or_where(); 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'); 感谢楼上,试试! mark. $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')
看手册啊。。看手册。 我觉得直接写sql语句方便啊,大家说说呢?还有那个table类也是这样,我直接写table表格,如果配合jquery,那就更方便了。 乌有 发表于 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 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