title: pass two query result to view in codeigniter
body: <p>i have two query $q1 and $q2.
  from the query1 i get multiple records and each record having id and i want use this id for second query in  where condition.</p>
  
  <p>i am doing this in controller.
  i have tried following code.
  In the foreach i am trying to store id and pass to $q2 where condition.</p>
  
  <pre><code>//Query 1
      $q1 = $this-&gt;db-&gt;select(array(
                                   'spf.id as id' ,
                                    'spf.name',
                                  'spf.added_on'
                                  ))-&gt;from('sp_form spf')-&gt;where($where)-&gt;order_by('spf.id desc')-&gt;limit(10, $page * 10)-&gt;get();
                     $data['data'] = $q1-&gt;result_array();
  
                  foreach($data as $rec)
                  {
                     $id = $rec['id']; // here how i catch id for each row
  
                   //Query 2
  
                      $q2 = $this-&gt;db-&gt;select("count('id') as count ")-&gt;from('sp_topic spft')-&gt;where('spft.formid',$id)-&gt;get();
                        $data['count'] =  $q1-&gt;row_object();
                  }
                  // pass combine result to view
  
                   $this-&gt;load-&gt;view('myview', $data,true);
  </code></pre>
  
  <p>Edit:</p>
  
  <pre><code>This is my view.
  
  I have try Nishant answer and i get resultq1 using foreach but how can i get result of resultq2.
  
  
      &lt;table width="100%"&gt;
        &lt;tr&gt;
          &lt;td class="th"&gt; Details&lt;/td&gt;
          &lt;td width="5%" class="th"&gt; Answer&lt;/td&gt;
          &lt;td width="15%" class="th"&gt;Started by&lt;/td&gt;
          &lt;td  width="15%" class="th"&gt;Created on&lt;/td&gt;
        &lt;/tr&gt;
        &lt;?php foreach($resultq1 as $row):?&gt;
         &lt;tr&gt;
          &lt;td&gt;&lt;?php echo $row['name'] ;?&gt;&lt;/td&gt;
  
           &lt;td &gt;---- &lt;/td&gt; // here i want to use resultq2
  
           &lt;td&gt;&lt;?php echo $row['added_by'] ;?&gt;&lt;/td&gt;
          &lt;td &gt;&lt;?php echo $row['added_on'];?&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;?php endforeach;?&gt;
      &lt;/table&gt;
  </code></pre>