我希望这里需要实现适当的递归逻辑。我需要为我的树创建一个动态循环结构。所有数据都将来自数据库,并自动显示到其受尊重的位置。
function setTree($persons)
{
$tree='';
foreach($persons as $key)
{
// echo $key->name;
// if($key->child_id > 0)
// {
// $ci =& get_instance();
// //echo $key->child_id;
// $remain_persons=$ci->Main_M->get('tbl_user','id','ASC','father_id',$key->id);
// echo '<pre>';
// print_r($remain_persons);
// setTree($remain_persons);
// }
// echo '<br />';
$tree ='<li>
<div>
<span>Sue Mighty</span>
<span></span>
<span>Jim Snow</span>
</div>';
if($key->child_id > 0)
{
$ci =& get_instance();
$remain_persons=$ci->Main_M->get('tbl_user','id','ASC','father_id',$key->id);
$tree .='<ul>';
$tree='
<li>
<div><span>Brie Snow</span></div>
</li>';
$tree .='</ul>';
setTree($remain_persons);
}
$tree .= '</li>';
}
echo $tree;
}
setTree($persons);