Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda