php父类与子类读取数据代码是一填二级分类的程序代码,该程序可以根据父的数据查找出其子类的数据,代码如下:
- function getsubcomments($parent = 0, $level = 0) {
- $db = &jfactory::getdbo();
- $sql = "...";
- $db->setquery($sql);
- $rows = $db->loadobjectlist();
- $list = array();
-
- foreach ($rows as $row) {
- $row->level = $level;
- $list[] = $row;
- $tmparr = getsubcomments($row->id, $level + 1);
- if (count($tmparr)) {
- foreach ($tmparr as $tmprow) {
- $list[] = $tmprow;
- }
- }
- }
- return $list;
- }
- $list = array();
- foreach ($tmplist as $row) {
- $row->level = 0;
- $list[] = $row;
- $tmplist2 = getsubcomments($row->id, 1);
- foreach ($tmplist2 as $row2) {
- $list[] = $row2;
- }
- }
-
- if ($row->level) {
- $pre = '';
- for ($n = 0; $n < $row->level; $n++)
- $pre .= '----';
- echo $pre . '|- ';
- }
- echo strip_tags($row->content);
|