Copy CodeThe code is as follows:
function getsubcomments ($parent = 0, $level = 0) {
$db = &jfactory::getdbo ();
$sql = "..."; SQL for querying records
$db->setquery ($sql);
$rows = $db->loadobjectlist ();
$list = Array ();
First get the recordset from the data, then add level to the record, the parent level = 0, its lower level = 1, and so on
foreach ($rows as $row) {
$row->level = $level;
$list [] = $row;
$TMPARR = getsubcomments ($row->id, $level + 1); Recursive invocation
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;
}
}
Output content by level
if ($row->level) {
$pre = ";
for ($n = 0; $n < $row->level; $n + +)
$pre. = '----';
Echo $pre. '|- ';
}
Echo strip_tags ($row->content);
http://www.bkjia.com/PHPjc/322255.html www.bkjia.com true http://www.bkjia.com/PHPjc/322255.html techarticle Copy the code code as follows: function getsubcomments ($parent = 0, $level = 0) {$db = $sql = "..."; SQL $db-setquery ($sql) for querying records; $rows = $db-loadobjectlist (); $list = ar ...