title: Load multiple models within same function of controller code igniter
body: <p>I have a page where I want to display dynamic two select boxes.One select box get data from one model and then other select box get from other.Then after getting the data it will save the query or result of both of them and then view into one view page .</p>
  
  <p>I want to save the data in array of two queries and this is my controller:</p>
  
  <pre><code> function index(){
  
      $data['main_content'] = 'stockInView';
  
  
  
      $this-&gt;load-&gt;model('itemsModel');
      $query2 = $this-&gt;itemsModel-&gt;getAllItems();
      if ($query2)
      {
          $data['records'] = $query2;
  
      }
  
      $this-&gt;load-&gt;model('categoryModel');
      $query = $this-&gt;categoryModel-&gt;getAllCategories();
      if ($query)
      {
          $data['records'] = $query;
  
      }
  
  
      $this-&gt;load-&gt;view('dashboardTemplate/template',$data); 
      }
  </code></pre>
  
  <p>And then I display them in a foreach loop . But it is only able to display the 2nd query results or in this case display only categories in one select box and not the items in other select box.I am doing this for the first time so I don't know how to do it.</p>