Find data from 2 tables - PHP + CodeIgniter.

0

Hello, I'm starting my studies in codeIgniter and I came across following.

I have an employer table and another one of vacancies, the vacancy has id of the employer. I would like to display the data from the 2 tables. For example: I type something and it will appear the data of the vacancy and the employer. To appear the job data I did:

Model:

function getVaga($campo_busca) {

$this->db
          ->select("*")
          ->from("dados_vaga")
          ->like('cargo',$campo_busca); 


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

}   

Already in the controller:

  public function teste(){

  $campo_busca = $this->input->post('teste');

  $data = array(
      "dados" => $this->Vaga_model->getVaga($campo_busca)
  );


  $this->load->view('busca', $data);

The employer id is in this table data_vaga to know who is the owner of this vacancy, now I do not know how to pass the same as a parameter to another query.

Good evening, thank you to everyone, big hug.

    
asked by anonymous 20.08.2016 / 02:37

1 answer

1

Try this:

function getVaga($campo_busca) {

     $this->db
          ->select("*")
          ->from("dados_vaga")
          ->join("dados_empregador", "dados_empregador.id = dados_vaga.id_empregador")
          ->like('dados_vaga.cargo',$campo_busca); 

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

}   

Obviously replace the "data_employer" and the ID fields between the 2 tables as needed.

More information about the JOIN in CI can be found at the link below: link

Good luck!

    
20.08.2016 / 03:00