Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!