PHP output content in hierarchical relationship
Function getsubcomments ($parent = 0, $level = 0) {
$db = &jfactory::getdbo ();
$sql = "..."; SQL
$db->setquery ($sql) for querying records;
$rows = $db->loadobjectlist ();
$list = Array ();
//Gets the recordset from the data, adds level to the record, the parent level = 0, it's subordinate levels = 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 $tmpR ow) {
$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;
}
}
//level of output
if ($row->level) {
$pre = ';
for ($n = 0; $n < $row->level; $n + +)
$pre. = '----';
Echo $pre. '|- ';
}
Echo strip_tags ($row->content);
http://www.bkjia.com/PHPjc/364650.html www.bkjia.com true http://www.bkjia.com/PHPjc/364650.html techarticle PHP outputs the content function getsubcomments ($parent = 0, $level = 0) as a hierarchy of levels {$db = Jfactory::getdbo (); $sql = ...;//Query records for SQL $ Db-setquery ($sql); $rows = $ ...