I want to join table dynamically in codeigniter by passing table name as parameter. below is my controller function to call model function
function index(){
$table=array('branch'=>'branch_id','specialization'=>'spec_branch_id');
$this->model->join($table);
}
and this is my model function
function join($table){
foreach($table as $table_name=>$table_id){
/*i want here table*/
$table1=$table_name;
}
$this->db->select('*');
$this->db->from(''.$table1.' t1');
$this->db->join(''.$table2.' t2','t1.'.$t1id.'=t2.'.$t2id);
return $this->db->get();
echo $this->db->last_query();die;
}
As in above function i want dynamic table name like table1=branch; table2=specializaton in my model function, so please help me to solve and if someone have another also can share.