Join Codeigniter

Asked

Viewed 2,977 times

1

Next guys, I have a vague table and other vaga_cadidato, I would like to select the data of the same when the id_entity is equal in the id_entity. However it is showing me only the data of the vacant table, I would like in this same query to show the data of the vaga_candidate. Follow my query.

function vagaDaEntidade(){
  $status = 'Aguardando Reposta';
  $id_entidade = $this->session->userdata('id_entidade');
  $this->db
  ->select("*")
  ->from("vaga")
  ->join('vaga_candidato', 'vaga.id_vaga = vaga_candidato.id_vaga')
  ->where('status_vaga', $status);


  return $query = $this->db->get()->result();
}

Hug to all.

  • Your database has the right relationships in the tables?

  • When you make a print_r(); in the query variable, is returning the name of its table columns vaga_candidato?

1 answer

1

Specify the tables in select. Try it this way and it will work:

$this->db
  ->select("vaga.*, vaga_candidato.*")
  ->from("vaga")
  ->join('vaga_candidato', 'vaga.id_vaga = vaga_candidato.id_vaga')
  ->where('status_vaga', $status);

That’s all!

  • Exactly that! And if you happen to have a field with the same name in both tables use an ALIAS.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.