0
I have the following method to obtain data in codeigniter.
// Obter Fase
public function obter_fase($id)
{
$this->db->from($this->tbl_empresa_fase);
$this->db->select("tbl_empresa_fase.*, IF(tbl_empresa_fase.crud = 'C', 'R', 'C') as crud", FALSE);
if (is_array($id))
{
$this->db->where_in('campanha_id',$id);
}
else
{
$this->db->where('campanha_id',$id);
}
$this->db->order_by('campanha_id');
$query = $this->db->get();
$item = $query->result_array();
return $item;
}
It works, but if the ID being searched does not exist in the database, an error is returned and with the above method, this is expected.
For this reason, I want to know if there is possibility to create a condition that checks if the ID sought exists in the database.
If yes, returns the result_array
, if not, returns return []
.
Before the
return
what I have in$item
when the$id
there is no?– Erlon Charles
If there is no error..
– Wagner Fillio
What mistake, what line?
– Erlon Charles
I will try your answer, but check the error:: Error Number: 1064 You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near ') ORDER BY
campanha_id
' at line 3 SELECT tbl_empresa_fase. *, IF(tbl_empresa_fase.crud = 'C', 'R', 'C') as crud FROMtbl_empresa_fase
WHERE campanha_id IN() ORDER BYcampanha_id
– Wagner Fillio