title: Foreach loop problem in model using Codeigniter
body: <p>Model:</p>
  
  <pre><code>public function fetch_emp()   
  { 
     $this-&gt;db-&gt;select('emp_id');
     $this-&gt;db-&gt;from('emp');
     $res=$this-&gt;db-&gt;get();
     foreach($res-&gt;result() as $row)
    {
        $id=$row-&gt;emp_id;
        $this-&gt;db-&gt;select('emp_name');
        $this-&gt;db-&gt;from('employee_master');
        $this-&gt;db-&gt;where('emp_id',$id);
        $res=$this-&gt;db-&gt;get();
        return $res-&gt;result();
     }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public function employee()
  {
    $result=$this-&gt;emp_model-&gt;fetch_emp();
    if($result!=false)
      $res['cmp_name']=$result;
    else
      $res['cmp_name']='NA';
  }
    $this-&gt;loadViews("emp/emp_views", $this-&gt;global, $res , NULL);
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;?php print_r($cmp_name);?&gt;
  </code></pre>
  
  <p>Once I fetch the id from db I got all the id not problem at all, but when I used in foreach loop to search the id and get their names from another db It display only the 1st id name...  For eg:If there are 5 id, but when I search the id to get the name from another db it shows the 1st id name only.What's the problem I don't know pls help me. </p>