简体   繁体   中英

Codeigniter active record how to join five tables

I have the following database schema 在此输入图像描述

I am using codeigniter.I need to get data from all the tables ,by giving id of question_banks table.So how should I write the join clause for this using active record class of codeigniter.I know it is possible to join two tables.But how can I join all these tables.

It is not the best one but I think it will help

$this->db->select('questions.question, question_categories.name, options.value, question_banks.name');    
$this->db->from('questions');
$this->db->join('question_categories', 'questions.question_category_id = question_categories.id');
$this->db->join('options','options.option_id=questions.id');
$this->db->join('question_bank_questions', 'questions.id = question_bank_questions.question_id');
$this->db->join('question_banks', 'question_bank_questions.question_bank_id = question_bank.id');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM