title: How to style codeigniter multi level menu?
body: <p>I want to create a multi level menu with codeIgniter.</p>
  
  <p>My table structure is this:</p>
  
  <blockquote>
    <p>id -- category -- parent_id</p>
  </blockquote>
  
  <p>I use this code in my model:</p>
  
  <pre><code>function all_category_ordered($level = 0, $prefix = '&lt;li&gt;') {
      $rows = $this-&gt;db
          -&gt;select('id,category,parent_id')
          -&gt;where('parent_id', $level)
          -&gt;order_by('id','asc')
          -&gt;get('category')
          -&gt;result();
  
      $category = null;
  
      if (count($rows) &gt; 0) {
  
          foreach ($rows as $row) {
              $category .= $prefix . $row-&gt;category . "\n";
              // Append subcategories
              $category .= "&lt;/li&gt;".$this-&gt;all_category_ordered($row-&gt;id, $prefix . '*') ;
          }
      }
      return $category;
  }
  </code></pre>
  
  <p>it works fine and the out put of the code is like this:</p>
  
  <pre><code>&lt;li&gt;menu 1&lt;/li&gt;
  &lt;li&gt;menu 2&lt;/li&gt;
  &lt;li&gt;menu 3&lt;/li&gt;
  &lt;li&gt;*submenu 1&lt;/li&gt;
  &lt;li&gt;menu 4&lt;/li&gt;
  &lt;li&gt;*submenu 2&lt;/li&gt;
  </code></pre>
  
  <p>but I want to change the model to out put in <code>ul</code> and <code>li</code> correct order to style it correctly.</p>
  
  <p>preferred order:</p>
  
  <pre><code>&lt;ul&gt;
  &lt;li&gt;menu 1&lt;/li&gt;
  &lt;li&gt;menu 2&lt;/li&gt;
  &lt;li&gt;menu 3
  &lt;ul&gt;
  &lt;li&gt;*submenu 1&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;menu 3
  &lt;ul&gt;
  &lt;li&gt;*submenu 1&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Any help would be appreciated.</p>