2014-09-30 59 views
0

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

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%'); 

我想使用的活动记录类来做到这一点。

有什么想法?

感谢

+0

没关系,我在那里找到了答案。 [link] [1] [1]:http://stackoverflow.com/questions/6552821/codeigniter-parentheses-in-dynamic-active-record-query – 2014-09-30 04:48:10

回答

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