Because of their own a technical station, to the main article, some of the article is a series, so want to classify these articles, the same category in one below.
Good database design, nothing but id,fatherid to classify, Fatherid on behalf of the parent is that article Id,id is the article's unique ID, the level is not limited, can be two layers, can be three layers. The Fatherid is a 0 representation of the top story.
PHP code, mainly recursive
function Category_tree ($fatherid) {//require_once ("mysql_class/config.inc.php");
Require_once ("mysql_class/database.class.php");
$db = new Database (Db_server, Db_user, Db_pass, db_database);
$db->connect (); $sql = "Select Id,title,url from".
Table_task. "
WHERE fatherid= $fatherid and ispublic=1 ORDER by ID ASC ";
$articles = $db->query ($sql);
$db->close ();
while ($record = $db->fetch_array ($articles)) {$i = 0;
if ($i = = 0) {if ($fatherid ==0) {echo ' <ul class= ' Article-list-no-style border-bottom ' > ';
}else{Echo ' <ul class= ' article-list-no-style ' > '; } if ($fatherid ==0) {echo ' <li><span class= ' Glyphicon glyphicon-log-in ' aria-hidden= ' True ' id= ' Han '. $record [' id ']. ' " > </span> <a href= "'. $record [' url ']. ' target= ' _blank ' > '. $record [' title ']. '
</a> '; }else{Echo ' <li><span class= ' Glyphicon Glyphicon-chevroN-right "aria-hidden=" true "> </span> <a href=" '. $record [' url ']. ' target= ' _blank ' > '. $record [' title ']. '
</a> ';
} category_tree ($record [' id ']);
Echo ' </li> ';
$i + +;
if ($i > 0) {echo ' </ul> ';
}
}
}
Call:
Category_tree (0)//First extract the top story
The above mentioned is the entire content of this article, I hope you can enjoy.