Welcome Guest, Not a member yet? Register   Sign In
Mysql query question about using active record
#3

[eluser]Phil Sturgeon[/eluser]
Yea sure you can use brackets. Its not entirely obvious at first, but remember that all AR does is to join strings. So if you have:

Code:
$this->db->where('foo, $var1);
$this->db->where('( bar, $var1);
$this->db->orwhere('blobby = '.$var2.')');

This will create:

Quote:WHERE foo = var1 AND (bar = var1 OR blobby = var2)

Of course this is a bit confusing, so you may find it easier to use AR as normal, but put your complex WHERE statements in a single where line. For example...

Code:
$this->select('whatever');
$this->db->join('table', 'table.id = othertable.id');
$this->db->where('WHERE foo = '.$var1.' AND (bar = '.$var1.' OR blobby = '.$var2.')');


Messages In This Thread
Mysql query question about using active record - by El Forum - 01-12-2008, 08:11 AM
Mysql query question about using active record - by El Forum - 01-12-2008, 08:22 AM
Mysql query question about using active record - by El Forum - 01-12-2008, 08:25 AM
Mysql query question about using active record - by El Forum - 01-12-2008, 09:01 AM
Mysql query question about using active record - by El Forum - 01-12-2008, 12:14 PM
Mysql query question about using active record - by El Forum - 01-14-2008, 06:05 AM
Mysql query question about using active record - by El Forum - 01-14-2008, 11:47 AM
Mysql query question about using active record - by El Forum - 08-29-2008, 12:14 AM
Mysql query question about using active record - by El Forum - 08-29-2008, 06:21 AM
Mysql query question about using active record - by El Forum - 08-31-2008, 08:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB