title: How to join table dynamically in codeigniter?
body: <p>I want to join table dynamically in codeigniter by passing table name as parameter.
  below is my controller function to call model function </p>
  
  <pre><code>function index(){  
  $table=array('branch'=&gt;'branch_id','specialization'=&gt;'spec_branch_id');
  $this-&gt;model-&gt;join($table);
  }
  </code></pre>
  
  <p>and this is my model function</p>
  
  <pre><code>function join($table){
  
      foreach($table as $table_name=&gt;$table_id){  
          /*i want here table*/       
          $table1=$table_name;
      }
      $this-&gt;db-&gt;select('*');
      $this-&gt;db-&gt;from(''.$table1.' t1');
      $this-&gt;db-&gt;join(''.$table2.' t2','t1.'.$t1id.'=t2.'.$t2id);
  
      return $this-&gt;db-&gt;get();
  
      echo $this-&gt;db-&gt;last_query();die;
  }
  </code></pre>
  
  <p>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.</p>