How to get data from multiple tables at once?
I need to retrieve data from the following object (debtor).
There are several tables, where the main table is tbl_devedor
.
After that, there are others, which are related to tbl_devedor
.
Example:
-
tbl_devedor
-
tbl_email
-
id_contrato
-
id_telefone
-
id_endereco
Below is array
$dados = array(
'contratos' => [],
'id' => '',
'id_operador' => 0,
'pessoa_fisica' => array(
'id' => 0,
'rg' => '',
'dt_nascimento' => '',
'profissao' => '',
'salario' => '',
'genero' => '',
),
'pessoa_juridica' => array (
'id' => 0,
'nome_fantasia' => '',
'inscricao_estadual' => ''
),
'nome' => '',
'cpf_cnpj' => '',
'emails' => [],
'enderecos' => [],
'telefones' => [],
'crud' => null
);
echo json_encode($dados);
Remembering that contratos
, pessoa_fisicao
, pessoa_juridica
, emails
, enderecos
, telefones
, comes from different tables, so far what I have is this:
Controller
$devedor = $this->devedor->obter_por_id($id);
Model
public function obter_por_id($id)
{
$this->db->from($this->tbl_devedor);
$this->db->where('id',$id);
$query = $this->db->get();
return $query->row();
}
I know how to join and get the data from the other tables, but I do not know how to get the structure of array
.