Home > Backend Development > PHP Tutorial > PHP outputs content according to the hierarchical relationship between upper and lower levels_PHP tutorial

PHP outputs content according to the hierarchical relationship between upper and lower levels_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 14:54:17
Original
1364 people have browsed it

PHP outputs content according to the hierarchical relationship between upper and lower levels

function getSubComments($parent = 0, $level = 0) {
$db = &JFactory::getDBO();

$sql = "..."; // Query records SQL
$db->setQuery($sql);
$rows = $db->loadObjectList();

$list = array();

/ / First get the record set from the data, then add level to the record, the parent level = 0, its subordinate 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 hierarchically by level
if ($row->level) {
$pre = '';
for ($n = 0; $n < ; $row->level; $n++)
$pre .= '----';

echo $pre . '|- ';
}
echo strip_tags( $row->content);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364650.htmlTechArticlePHP outputs content according to the superior and subordinate hierarchical relationship function getSubComments($parent = 0, $level = 0) { $db = JFactory::getDBO(); $sql = ...; // SQL query for records $db-setQuery($sql); $rows = $...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template