[eluser]Unknown[/eluser]
hello, I'm having a problem with a query using Active Record, when many use conditions.
The Model code is:
Code:
function listar_softwares($args = array())
{
extract($args);
$this->db->select('s.*, di.nome AS distribuicao, s.data_cadastro AS data');
$this->db->from('softwares AS s');
$this->db->join('distribuicao AS di','s.id_distribuicao = di.id_distribuicao','inner');
$this->db->join('descricao_softwares AS de','s.id_software = de.id_software','inner');
$this->db->where('s.status',1);
$this->db->where('di.status',1);
if(!empty($distribuicao))
$this->db->where('s.id_distribuicao',$distribuicao);
if(!empty($categoria))
$this->db->where('s.id_categoria',$categoria);
if(!empty($plataforma))
$this->db->like('s.plataforma',$plataforma);
if((!empty($pagina)) && (!empty($registros)))
$this->db->limit($registros,$pagina);
if(!empty($busca))
{
$campos = explode(',',$campo_busca);
$h=0;
foreach($campos as $campo)
{
if($h == 0)
$this->db->like($campo,$busca);
else
$this->db->or_like($campo,$busca);
$h++;
}
}
$query = $this->db->get();
return $query->result_array();
}
Passing the parameters correctly, he returns the following query:
Code:
SELECT `s`.*, `di`.`nome` AS distribuicao, `s`.`data_cadastro` AS data
FROM (`softwares` AS s)
INNER JOIN `distribuicao` AS di ON `s`.`id_distribuicao` = `di`.`id_distribuicao`
INNER JOIN `descricao_softwares` AS de ON `s`.`id_software` = `de`.`id_software`
WHERE `s`.`status` = 1
AND `di`.`status` = 1
AND `s`.`id_distribuicao` = '3'
AND `s`.`id_categoria` = '214'
AND `s`.`plataforma` LIKE '% 98 %'
AND `s`.`nome` LIKE '% dragon %'
OR `s`.`des_pequena` LIKE '% dragon %'
OR `de`.`des_longa` LIKE '% dragon %'
LIMIT 1, 50
The problem is that between the results returned, the information is not completely identical, for example, some results have the 's'. 'Id_distribuicao' different from 3.
I believe, to use "( )" - brackets - and solve the problem but how to do this using the Active Record to CodeIgniter?
Sorry if there are grammatical errors, I used google translate.
Thanks!