Copy codeThe Code is as follows:
Function getSubComments ($ parent = 0, $ level = 0 ){
$ Db = & JFactory: getDBO ();
$ SQL = "..."; // SQL statement used to query records
$ Db-> setQuery ($ SQL );
$ Rows = $ db-> loadObjectList ();
$ List = array ();
// Obtain the record set from the data first, then add level to the record, 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 call
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;
}
}
// Output content by level
If ($ row-> level ){
$ Pre = '';
For ($ n = 0; $ n <$ row-> level; $ n ++)
$ Pre. = '----';
Echo $ pre. '| -';
}
Echo strip_tags ($ row-> content );