title: Show and list data base on each category from database with codeigniter
body: <p>i'm trying to show and list data base on each category from database with codeigniter. </p>
  
  <p><strong>Table structure:</strong></p>
  
  <p><em>Category</em>: id_cat, name_cat</p>
  
  <p><em>Subcategory</em>: id_subcat, id_cat, name_subcat</p>
  
  <p>I want the output like this:</p>
  
  <ol>
  <li>Car
  
  <ul>
  <li>Lamborghini</li>
  <li>Ford</li>
  <li>Nissan</li>
  </ul></li>
  <li>Bike
  
  <ul>
  <li>Honda</li>
  <li>Yamaha</li>
  </ul></li>
  <li>Airplane
  
  <ul>
  <li>Boeing</li>
  </ul></li>
  </ol>
  
  <p>But, when i run my code it show like this:</p>
  
  <ol>
  <li>Car
  
  <ul>
  <li>Lamborghini</li>
  <li>Ford</li>
  <li>Nissan</li>
  </ul></li>
  <li>Bike
  
  <ul>
  <li>Lamborghini</li>
  <li>Ford</li>
  <li>Nissan</li>
  </ul></li>
  <li>Airplane
  
  <ul>
  <li>Lamborghini</li>
  <li>Ford</li>
  <li>Nissan</li>
  </ul></li>
  </ol>
  
  <p>My code:</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>$this-&gt;data['get_category'] = $this-&gt;Category_model-&gt;get_all_sidebar();
  $this-&gt;data['get_subcat'] = $this-&gt;Subcategory_model-&gt;get_all_sidebar();
  $this-&gt;load-&gt;view('front/body', $this-&gt;data);
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <p><em>Category</em>:</p>
  
  <pre><code>public function get_all_sidebar()
  {
    return $this-&gt;db-&gt;get($this-&gt;table)-&gt;result();
  }  
  </code></pre>
  
  <p><em>Subcategory</em>:</p>
  
  <pre><code>public function get_all_sidebar()
  {
    $this-&gt;db-&gt;select('*');
    $this-&gt;db-&gt;join('category', 'category.id_cat = subcategory.id_cat');
    $this-&gt;db-&gt;order_by('id_subcat', 'ASC');
    return $this-&gt;db-&gt;get('subcategory')-&gt;result();
  }  
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>&lt;?php
  echo '&lt;ul class="category"&gt;';
  foreach($get_category as $category)
  {
    echo "&lt;li&gt;$category-&gt;name_cat&lt;/li&gt;";
  
    echo "&lt;ul&gt;";
    foreach($get_subcat as $subcat)
    {
      echo "&lt;li&gt;$subcat-&gt;name_subcat&lt;/li&gt;";
    }
      echo "&lt;/ul&gt;";
  
  }
  echo "&lt;/ul&gt;";
  ?&gt;
  </code></pre>
  
  <p>Any help will be so appreciate, thank you</p>