title: How to use two tables data in a view in Codeigniter
body: <p>I have two tables, first table is about topic name and second table shows sub-topics. I want to show from first table topic name then search their corresponding sub-topic and show it in view and so on till topic names are found in first table. But the problem is i can only get one table data in view i.e. main topic table. I have no idea how to get full data of both table and use it.</p>
  
  <blockquote>
    <p>Database Structure:</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/1od4O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1od4O.png" alt="enter image description here"></a></p>
  
  <blockquote>
    <p>Model:</p>
  </blockquote>
  
  <pre><code>&lt;?php 
  
      class Topics_Model extends CI_Model {
  
      function __construct()
          {
                parent::__construct();
          }
  
      function get_all_topics()
      {
         $this-&gt;load-&gt;database();
         $this-&gt;db-&gt;select("*");
         $this-&gt;db-&gt;from("topics");
         $query=$this-&gt;db-&gt;get();
         return $query-&gt;result();
      }
      }
  </code></pre>
  
  <p>?></p>
  
  <blockquote>
    <p>Controller :</p>
  </blockquote>
  
  <pre><code>&lt;?php
  
  class drag_drop_course_material extends CI_Controller {
  
    function drag_drop_course_material()
     {
       parent::__construct();
     }
  
     function index()
      {
       $this-&gt;load-&gt;model('topics_model');
       $data['query']=$this-&gt;topics_model-&gt;get_all_topics();
       $this-&gt;load-&gt;helper('url');
       $this-&gt;load-&gt;view('drag_drop_course_material', $data);
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>View:</p>
  
  <pre><code> &lt;?php
      foreach ($query as $row) {
   ?&gt;
     &lt;li&gt;  $row-&gt;topic_name   &lt;/li&gt;
   &lt;? }  ?&gt;
  </code></pre>
  
  <p>Required Output:</p>
  
  <p><a href="https://i.stack.imgur.com/m2QaL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m2QaL.png" alt="enter image description here"></a></p>