function getsubcomments ($parent = 0, $level = 0) { $db = &jfactory::getdbo (); $sql = "..."; SQL for querying records $db->setquery ($sql); $rows = $db->loadobjectlist (); $list = Array (); Get the recordset from the data, then add the level to the record, the parent levels = 0, and its subordinate rank = 1, and so on. foreach ($rows as $row) { $row->level = $level; $list [] = $row; $tmparr = getsubcomments ($row->id, $level + 1); Recursive call if (count ($tmparr)) { foreach ($tmparr as $tmprow) { $list [] = $tmprow; } } } return $list; } $list = Array (); foreach ($tmplist as $row) { $row->level = 0; $list [] = $row; $tmplist 2 = getsubcomments ($row->id, 1); foreach ($tmplist 2 as $row 2) { $list [] = $row 2; } } Hierarchical output by level if ($row->level) { $pre = '; for ($n = 0; $n < $row->level; $n + +) $pre. = '----'; Echo $pre. '|- '; } Echo strip_tags ($row->content); |