大家好!我的代码有问题,这段代码的功能是从上到下显示来自一个单亲的所有孩子。但问题是我被三级孩子困住了。我想要的是让所有的孩子不使用重复编码,就像你们在下面看到的那样:
<div>
<div>
<?php
echo $root; //Parent head
?>
</div>
<?php
foreach ($row => $value){ //Set all values which has parent_id of $root to $value
?>
<div style="float:<?php echo $value['position']; ?>;">
<?php echo $value['childusername']; ?> //Display Child
<?php
$under2 = getchildofchild($value['codezone'],$value['root_id'],$value['childusername']);
foreach ($under2 as $row2 => $value2){?><br>
<div style="float:<?php echo $value2['position']; ?>;">
<?php echo $value2['childusername']; ?>
<?php
$under3 = getchildofchildofchild($value2['codezone'],$value2['root_id'],$value2['username']);
foreach ($under3 as $row3 => $value3){?><br>
<div style="float:<?php echo $value3['position']; ?>;">
<?php echo $value3['childusername']; ?>
</div>
<?php
}
?>
</div>
<?php
}
?>
</div>
<?php
}
?>
<div style="clear:both;"></div>
</div>
然后我希望它看起来像二叉树样式视图。我的数据库如下所示:
+----+----------+
| id | sponsorID |
+----+----------+
| 1 | NULL |
| 2 | 1 |
| 3 | 1 |
| 4 | 2 |
| 5 | 2 |
| 6 | 3 |
| 7 | 3 |
| 8 | 4 |
| 9 | 4 |
+----+----------+
提前致谢!