Welcome Guest, Not a member yet? Register   Sign In
Advanced SQL queries with Active Record
#1

[eluser]Kyle Ellman[/eluser]
Hello, I am having some issues using the active record class to do a search on some users in a database.

I need to use multiple "where" clauses and multiple "like" clauses.

The "where" clauses are all mandatory as they are flags that all need to be a certain way.

I want to take any matches from any of the "like clauses," so I need to use the or_like functions on all but one of them, I think. The problem is that as soon as I use an or_like, it renders my "where" clauses useless.

Essentially, I think it's doing this: (where f1 equals s1 AND where f2 equals s2 AND f3 isLike s3) OR f4 isLike s4

But I need it to do this: (where f1 equals s1 AND where f2 equals s2) AND (f3 isLike ss32 OR f4 isLike s4)

(I know, the SQL syntax is wrong, but hopefully I got the point accross)

Does anyone have any ideas?

Thanks.
#2

[eluser]jmadsen[/eluser]
Hey Kyle,

Active Record has no parenthesis.

if you want to stick to using it, I the custom where clause is your best bet:

Code:
$where = "name='Joe' AND status='boss' OR status='active'";

$this->db->where($where);

and just set it up exactly as you want it
#3

[eluser]Kyle Ellman[/eluser]
Good call. It's working like a charm.

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB