用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3198|回复: 15
收起左侧

[HELP] 求助~~Ci的where复杂语句查询

[复制链接]
发表于 2014-10-27 15:16:55 | 显示全部楼层 |阅读模式
本帖最后由 zsy0228 于 2014-10-27 15:20 编辑

表名:aaa
字段:
    uid
   to_uid
   status
  求助内容:
    查询 uid 或 to_uid 等于2 的 status等于1

请大神帮助俺~~~~~


发表于 2014-10-28 10:32:58 | 显示全部楼层
$this->db->where('(uid=2');
$this->db->or_where('to_uid=2)');
$this->db->where('status', 1);

以前我也遇到过这个问题,后来就是类似这样处理的;
注意字符串里面有()
 楼主| 发表于 2014-10-27 15:28:17 | 显示全部楼层
Closer 发表于 2014-10-27 15:23
使用多個 $this->db->where();
他會自動幫你 AND 所有 where 資料

就是说,我想查出uid=2&&status=1   还有  to_uid=2&& status=1的所有
 楼主| 发表于 2014-10-27 15:20:04 | 显示全部楼层
上面错了,是这个 查询 uid 和 to_uid 等于2 ,status等于1
发表于 2014-10-27 15:20:12 | 显示全部楼层
是要找 uid = 2, to_uid = 2, status = 1 的資料?
 楼主| 发表于 2014-10-27 15:20:21 | 显示全部楼层
  查询 uid 或 to_uid 等于2 ,status等于1
 楼主| 发表于 2014-10-27 15:21:23 | 显示全部楼层
Closer 发表于 2014-10-27 15:20
是要找 uid = 2, to_uid = 2, status = 1 的資料?

是~~~~~~~~~~~~~~~~
 楼主| 发表于 2014-10-27 15:22:30 | 显示全部楼层
Closer 发表于 2014-10-27 15:20
是要找 uid = 2, to_uid = 2, status = 1 的資料?

  查询 uid 或者 to_uid 等于2 ,status等于1


发表于 2014-10-27 15:23:53 | 显示全部楼层
使用多個 $this->db->where();
他會自動幫你 AND 所有 where 資料
 楼主| 发表于 2014-10-27 15:24:55 | 显示全部楼层
Closer 发表于 2014-10-27 15:23
使用多個 $this->db->where();
他會自動幫你 AND 所有 where 資料

这个uid 和to_uid是 或者 关系

发表于 2014-10-27 15:30:57 | 显示全部楼层
試試

$this->db->where('uid', 2);
$this->db->or_where('to_uid', 2);
$this->db->like('status', 1, 'none');

本版积分规则