Database Classification Query related issues

Source: Internet
Author: User
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;
}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.