mysql - Using CodeIgniter Active Record statements -


i'm looking way use active record in codeigniter build query.

my current code this:

$this->db->   like('responsible', $user->id); $this->db->or_like('accountable', $user->id); $this->db->or_like('consulted',   $user->id); $this->db->or_like('informed',    $user->id);  // tasks, correct start or end date $tasks = $this->db->get_where('level_' . $this->config->item('answer_level'), array('date_end' => $offset, 'ccode' => $user->country));  // check if tasks exist if($tasks->num_rows() > 0){     // tasks have been found should have been finished!     echo $tasks->num_rows() . " tasks found " . $user->first_name . " should have been finished!\n";     $last_month_tasks = $tasks->result(); }  unset($tasks); 

which produces following sql:

select * (`level_3`) `date_start` =  -5 , `ccode` =  'gb' ,  `responsible`  '%5%' or  `accountable`  '%5%' or  `consulted`  '%5%' or  `informed`  '%5%'  

but need produce sql:

select *  (`level_3`)  `date_start` = -5 ,  `ccode` =  'gb' , ( `responsible`  '%5%'     or  `accountable`  '%5%'     or  `consulted`  '%5%'     or  `informed`  '%5%' ) 

codeigniter's activerecord not support nesting of queries , clauses. have manually this:

$this->db->select('*'); $this->db->from('level_' . $this->config->item('answer_level')); $this->db->where(array('date_end' => $offset, 'ccode' => $user->country)); $this->db->where("(responsible '%5%' or accountable '%5%' or consulted '%5%' or informed '%5%')"); $tasks = $this->db->get(); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -