Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
CodeIgniter with database selection:

I have two tables questions and answers. In table questions there are two columns id and que. In table answers columns are id, que_id, option1, optoin2 option3, option4. I want to print question and then its options.

$this->db->select('*');
$this->db->from('questions');
$this->db->join('answers', 'answers.que_id = questions.id', 'left');
$query = $this->db->get();

after this code I get print 4 times question with its options.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Well, the join method will not help you in this case.

Try this:

$questions = $this->db->select('*')->from('questions')->get()->result();

foreach ($questions as &$question) {
    $question->answers = $this->db->select('*')->from('answers')->where('que_id', $question->id)->get()->result();
}

Now you can navigate through the $questions object and get the respective answers.

Hope I've helped a little.

over 4 years ago · Santiago Trujillo Relatório

0

try this way

$this->db->select('answers.option1,answers.option2,answers.option3,answers.option4,questions.que');
$this->db->from('answers');
$this->db->join('questions', 'answers.que_id = questions.id');
$query = $this->db->get();
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda