Braian Mellor Braian Mellor - 17 days ago 8
MySQL Question

Codeigniter where statement with parenthesis

What i'm traying to do is to set into the where statement a parenthesis. Something like this:

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


But i don't want to do it with

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


I want to use the active record class.

Any idea?

Thanks

Answer
$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

Comments