There is a recursion in Codeigniter
function get_tree($pid) { $this->db->select('id, name, parent_id'); $this->db->where('parent_id',$pid); $tree = $this->db->get("catalog")->result_array(); $count = $this->db->count_all_results(); $html = ''; foreach ($tree as $row) { if ($row['parent_id'] == $pid) { $html .= '<li>' . "\n"; $html .= ' ' . $row['name'] . "\n"; $html .= ' ' . $this->get_tree($row['id']); $html .= '</li>' . "\n"; } } return $html ? '<ul>' . $html . '</ul>' . "\n" : ''; }
So, I call this:
echo "<ul class='menu'>"; echo $this->leftmenu->get_tree('0'); echo "</ul>";
And so the thing is, recursion starts and writes a new <*ul>
tag at the beginning, as a result of which my class menu
does not fall into the list. How to be?
That is, it turns out like this:
<ul class='menu'> <ul> <li>test</li> <li>test <ul><li>test_2</li> <li>test_2</li> </ul></li> <li>test</li> </ul> </ul>