Welcome Guest, Not a member yet? Register   Sign In
Group where statements together with active record
#1

[eluser]simshaun[/eluser]
I had a situation come up the other day where I needed to group a couple where statements together. Typically I use Active Record for all my database stuff, but I ended up hardcoding that specific SQL statement.

Is there a way to group where statements together with Active Record where the SQL generated is something along the lines of
Code:
SELECT
    id
FROM
    users
WHERE
    (first_name = 'John' AND age = 30)
        OR
    (first_name = 'John' AND height = 'tall')
        OR
    first_name = 'Bob'
#2

[eluser]Thorpe Obazee[/eluser]
[quote author="simshaun" date="1245894363"]I had a situation come up the other day where I needed to group a couple where statements together. Typically I use Active Record for all my database stuff, but I ended up hardcoding that specific SQL statement.

Is there a way to group where statements together with Active Record where the SQL generated is something along the lines of
Code:
SELECT
    id
FROM
    users
WHERE
    (first_name = 'John' AND age = 30)
        OR
    (first_name = 'John' AND height = 'tall')
        OR
    first_name = 'Bob'
[/quote]

Code:
$this->db->select('id')
$this->db->where("(first_name = John AND age = 30) OR (first_name = 'John' AND height = 'tall') OR first_name = 'Bob'")
$this->db->get('users')




Theme © iAndrew 2016 - Forum software by © MyBB