title: how to pass two result in same view in codeigniter
body: <p>i am new with codeigniter.I have written controller,model.view.</p>
  
  <p>I want to execute the another query in the model which having the "ID" from first model query in the where condition and pass the seperate results for both the both query in same view.</p>
  
  <p>i have explain it in model and view.
  how can i do this.need some syntax how can i do this.
  or is this correct way or do somwthing??</p>
  
  <p><b>Controller</b></p>
  
  <pre><code>class demo extends CI_Controller
  {
      function getRecords()
      {
          $offset = trim($this-&gt;input-&gt;get('off'));
          $this-&gt;load-&gt;model('demo_model');
          $data = $this-&gt;demo_model-&gt;get_messages($offset);
          $return = $this-&gt;load-&gt;view('demo_view',array('records'=&gt;$data),true);
          die($return);
      }   
  }
  </code></pre>
  
  <p><b>Model</b></p>
  
  <pre><code>class demo_model extends CI_Model
  {
      function get_messages($offset = 0)
      {
          $q = $this-&gt;db-&gt;query(" select Id,cloum2 from table");
  
          //  want to use ID from above query in to second query
  
          //  Like sql="select * from table where id='$id'" ; 
  
          //  and how i pass the separate result for both query inthe view
  
      return $q-&gt;result_array();
       }
  
  }
  </code></pre>
  
  <p><b>View</b> demo_view;</p>
  
  <pre><code>&lt;?php foreach($records as $row) :?&gt;
   &lt;div&gt; do something with $row &lt;/div&gt;
  
   &lt;div&gt; //want use second query foreach here  &lt;/div&gt;
  &lt;?php endforeach ;?&gt;
  </code></pre>