Codeigniter where括号括号

时间:2014-09-30 04:43:49

标签: mysql codeigniter where

我要做的是将where语句设置为括号。像这样:

SELECT
    `a_id`
FROM
    `auctions`
WHERE
    `a_state` = 1
AND (
    `p_name` LIKE '%XXX%'
    OR `at_name` LIKE '%XXX%'
    OR `p_code` LIKE '%XXX%'
)

但我不想用

来做
$this->db->query('SELECT  `a_id` FROM `auctions` WHERE  `a_state` =1 AND (`p_name` LIKE  '%XXX%' OR `at_name` LIKE  '%XXX%' OR  `p_code` LIKE  '%XXX%');

我想使用活动记录类。

有什么想法吗?

由于

1 个答案:

答案 0 :(得分:0)

$where="`a_state` =1 AND (`p_name` LIKE  '%XXX%' OR `at_name` LIKE  '%XXX%' OR  `p_code` LIKE  '%XXX%')";

    $this->db->select('a_id');
    $this->db->where($where);
    $this->db->from('auctions');
    $query = $this->db->get('');
echo  $this->db->last_query();// print the last query