zsy0228 发表于 2014-10-27 15:16:55

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

本帖最后由 zsy0228 于 2014-10-27 15:20 编辑

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

请大神帮助俺~~~~~


wlyx 发表于 2014-10-28 10:32:58

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

以前我也遇到过这个问题,后来就是类似这样处理的;
注意字符串里面有()

zsy0228 发表于 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的所有

zsy0228 发表于 2014-10-27 15:20:04

上面错了,是这个 查询 uid 和 to_uid 等于2 ,status等于1

Closer 发表于 2014-10-27 15:20:12

是要找 uid = 2, to_uid = 2, status = 1 的資料?

zsy0228 发表于 2014-10-27 15:20:21

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

zsy0228 发表于 2014-10-27 15:21:23

Closer 发表于 2014-10-27 15:20
是要找 uid = 2, to_uid = 2, status = 1 的資料?

是~~~~~~~~~~~~~~~~

zsy0228 发表于 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


Closer 发表于 2014-10-27 15:23:53

使用多個 $this->db->where();
他會自動幫你 AND 所有 where 資料

zsy0228 发表于 2014-10-27 15:24:55

Closer 发表于 2014-10-27 15:23
使用多個 $this->db->where();
他會自動幫你 AND 所有 where 資料

这个uid 和to_uid是 或者 关系

Closer 发表于 2014-10-27 15:30:57

試試

$this->db->where('uid', 2);
$this->db->or_where('to_uid', 2);
$this->db->like('status', 1, 'none');
页: [1] 2
查看完整版本: 求助~~Ci的where复杂语句查询