2014-09-30 89 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