我有2列的用户名和领导层次化查询
login_user sponsered_id right_left
test1 admin Right
test2 admin Left
test3 test1 Right
test4 test1 Left
test43 test2 Left
test44 test3 Left
我有一个函数
function display_children($parent, $level) {
// retrieve all children of $parent
$result = mysql_query('SELECT name, login_user, right_left FROM members_list '.
'WHERE sponsered_id="'.$parent.'";');
while ($row = mysql_fetch_array($result)) {
// indent and display the title of this child
echo '<tr><td>'.
$row['login_user'].' </td><td> '.$row['right_left'].' </td><td> '.$row['sponsered_id'].
"</td></tr>";
// call this function again to display this
// child's children
display_children($row['login_user'], $level+1);
}
}
echo display_children('admin',0);
,但没有得到正确的输出....它给人一种表我输出
test1 Right admin
test3 Right test1
test44 Left test3
test4 Right test1
test2 Left admin
test43 Left test2
需要输出
test1 Right admin
test2 Left admin
test3 Right test1
test4 Left test1
Right test2
test43 Left test2
Right test3
test44 Left test3
你说好好尝试一下比赛在数据库中的值输出: '右test2'多恩斯不存在。我认为你应该通过login_user来订购它们,你应该非常接近你所说的输出。 – Kao 2013-03-24 12:10:31
我想Kao建议,排序你的结果集可能会给你一个更理想的输出。 此外,我会推荐使用嵌套集模型hierarichal数据,它是更容易使用和遍历低谷节点和分支在您的层次结构。 – 2013-03-24 12:12:27
@Kao thats wt我的问题是有些值不是在右边或左边,它应该显示空白... – Harinder 2013-03-24 12:21:22