Я ищу способ использовать Active Record в CodeIgniter для построения моего запроса.
Мой текущий код:
$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);
// Get the tasks, but only with the 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 that should have been finished!
echo $tasks->num_rows() . " tasks found for " . $user->first_name . " that should have been finished!\n";
$last_month_tasks = $tasks->result();
}
unset($tasks);
При этом выдается следующий SQL:
SELECT *
FROM (`level_3`)
WHERE `date_start` = -5
AND `ccode` = 'GB'
AND `responsible` LIKE '%5%'
OR `accountable` LIKE '%5%'
OR `consulted` LIKE '%5%'
OR `informed` LIKE '%5%'
Но мне это нужно для создания этого SQL:
SELECT *
FROM (`level_3`)
WHERE `date_start` = -5
AND `ccode` = 'GB'
AND (
`responsible` LIKE '%5%'
OR `accountable` LIKE '%5%'
OR `consulted` LIKE '%5%'
OR `informed` LIKE '%5%'
)
Подробнее здесь: https://stackoverflow.com/questions/160 ... nd-where-c