[eluser]jvicab[/eluser]
if you like to have this solved without building the query yourself (like me), add this function in a system\database\DB_DB_active_rec.php:
function like_brackets()
{
// add a opening bracket
reset($this->ar_like);
$key = key($this->ar_like);
$this->ar_like[$key] = '(' . $this->ar_like[$key];
// add a closing bracket
end($this->ar_like);
$key = key($this->ar_like);
$this->ar_like[$key] .= ')';
// update the AR cache clauses as well
if ($this->ar_caching === TRUE)
$this->ar_cache_like[$key] = $this->ar_like[$key];
return $this;
}
and call it inside your model after the last like (or or_like) statement. Here is an example:
$this->db->from('tbl_work_listings,tbl_work_features');
$this->db->where(array('tbl_work_listings.PropertyID' => 'tbl_work_features.PropertyID'), null, false);
$this->db->like('FeatureDescription', 'ocean');
$this->db->or_like('FeatureDescription', 'waterfront');
$this->db->like_brackets();
It will create a query like this:
SELECT * FROM (`tbl_work_listings`, `tbl_work_features`)
WHERE tbl_work_listings.PropertyID = tbl_work_features.PropertyID
AND ( `FeatureDescription` LIKE '%ocean%' OR `FeatureDescription` LIKE '%waterfront%')
note: I have the same implemented by where.