<?php
$f_datas = $this->db->select('*')->from('表')->where('fid', 0)->get()->result_array();
foreach($f_datas as $f_num => $f_data)
{
$f_datas[$f_num]['childrens'] = $this->db->select('*')->from('表')->where('fid', $f_data['id'])->get()->result_array();
}
?>
<ul class="menu">
<?php foreach($f_datas as $f_data): ?>
<li class="level1">
<a href="#"><?php echo $f_data['name']; ?></a>
<ul class="level2">
<?php foreach($f_data['childrens'] as $f_childrens_data): ?>
<li><a href=""><?php echo $f_childrens_data['name']; ?></a></li>
<?php endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</ul>