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.
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.
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();