"Unknown column 'Array' in 'where clause'" - PHP + CodeIgniter

0

Hello, I have the following tables in the database:

  • data_vaga where it has several fields and one of them is id_vaga, id_academico.
  • sender_date where it has several fields and one is the following id_vaga.

When I save a job it has the id_vaga, which in the future when a person is going to register in the vacancy (table data_candidato) saves in it the id_vaga and the id_academico referring to the vacancy and the user in question.

So it will happen that a candidate has several vacancies to which the same has applied, how do I list those vacancies? So, as there are several id_vaga for the same candidate I do not know how to pass them to the query. I tried to do the following:

  function getMinhasVagas($id_academico){
  $id_academico = $this->session->userdata('id_academico');
  $this->db
          ->select("id_vaga")
          ->from("dados_candidato")
          ->where('id_academico', $id_academico );


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

    $this->db->select("*")->from("dados_vaga")->where('id_vaga', $qr);
    return $teste = $this->db->get()->result();

}
Returns the following error: Unknown column 'Array' in 'where clause'.

Thanks to anyone who answers me, have a nice day.

    
asked by anonymous 30.08.2016 / 18:08

2 answers

1

You tried to play the value of where an array ($ qr), which would be a kind of "IN".

Based on what you said I understood the following structure:

data_voice

  • id_vaga
  • Academic_id

candidate_date

  • id_vaga

I would solve this with a select only:

return $this->db->query("SELECT dv.*
                        FROM dados_vaga dv
                        INNER JOIN dados_candidato dc on dc.id_vaga = dv.id_vaga
                        WHERE dv.id_academico = ?", array($id_academico)
                       )->result();

or

$this->db->select('*');
$this->db->from('dados_vaga');
$this->db->join('dados_candidato', 'dados_candidato.id_vaga = dados_vaga.id_vaga');
$this->db->where("dados_vagas.id_academico", $id_academico);
return $this->db->get()->result();
    
30.08.2016 / 19:55
2

You can do something this way to access the property you need:

$this->db->select("*")->from("dados_vaga")->where('id_vaga', $qr->id_vaga);
    
30.08.2016 / 18:28