Database Classification Query problem
There is a classification table, the structure is like this
ID Name Father Categoryorder
1 A 0
2 B 0
3 A.1 1
4 A.2 1
5 a.1.a 3
6 a.1.b 3
7 B.1 2
Categoryorder I would like to use classification of the sorting, want to implement the classification to the tree display function, Categoryorder should be how to design?
A
--a.1
----a.1.a
----a.1.b
--a.2
B
--b.1
What should be done on PHP?
------Solution--------------------
LZ If your "classification table" is a database table, you should consider SQL to do the processing now.
According to your idea, you can build a field called "series." Sort by the order by group according to this series
SELECT * from good
ORDER by series
------Solution--------------------
static function Gettree ($depth, $parentID, $nodeID)
{
$str = "";
$nodes = D_node::getlistall ("Where parentid=". $parentID. "", "Orderflag desc");
if (count ($nodes) > 0) {
foreach ($nodes as $node) {
$str. = self::getprefixstring ($depth). $node->nodename;
$str. = Self::gettree ($depth + 1, $node->id, $nodeID);
}
}
return $str;
}
static function getprefixstring ($depth)
{
$STR = "--";
for ($i = 0; $i < $depth; $i + +) {
$str. = "--";
}
return $str;
}