"Unknown column 'Array' in 'Where clause'" - PHP+Codeigniter

Asked

Viewed 472 times

0

Hello, I have the following tables in the database:

  • data.
  • datos_candidate where the same has several fields and one is the following id_vaga.

When I save a vacancy the same has the id_vacancy, that in the future when a person will register in the vacancy (table data_candidate) saved in the same the id_vacancy and the academic id_concerning the vacancy and the user in question.

Only what will happen if a candidate has several vacancies to which he applied, how do I list those vacancies? Just that as there are several id_vaga regarding the same candidate I do not know how to pass the same 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'.

Thank you to all who answer me, have a good day.

2 answers

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);
  • I don’t know if I got it wrong, but $qr can have multiple results, in order to access $qr->id_vaga, he had to have used Row(). I think you’re wrong. In case I’m wrong I’m sorry.

  • @Murilo You are right, you must use Row() before you can access the property of the registry. However, I believe he wants only the first result, since he seeks a id specific to the wave.

1


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

Based on what you said I understood the following structure:

vacant data

  • id_vaga
  • id_academico

candidate data

  • id_vaga

I would settle 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();

Browser other questions tagged

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