Unlimited classification is mainly implemented by storing the id and path of the upper-level classification. Because the data structure is simple, to display the classification relationship in a tree, I can only think of implementing it in a recursive way. below is the structure of the classification data table and a tree display function written by myself, I hope you can point out something wrong. Table structure: the id field is a classification identifier, and the na class is unlimited. it is mainly implemented by storing the id and classification path of the parent class. Because the data structure is simple, to display the classification relationship in a tree, I can only think of implementing it in a recursive way. below is the structure of the classification data table and a tree display function written by myself, I hope you can point out something wrong.
Table structure: the id field is the category id, the name field is the category name, the father_id field is the id of the parent category, and the path field is the category path (the set of the ancestor of the category ), isdir is used to determine whether it is a directory (1 is yes, 0 is no ).
Display function:
// $ Count indicates the classification level
Sort_list ($ str, $ fatherid, $ count)
{
$ Rs = $ this-> SQL-> re_datas ("select * from sort where father_id = fatherid ");
$ Num = $ this-> SQL-> SQL _numrows ();
$ I = 0;
$ N = 1;
While (isset ($ rs [$ I])
{
$ Name = "";
For ($ n = 1; $ n <$ count; $ n)
{
$ Name. = "│ ";
}
If ($ I 1 = $ num)
{
$ Name. = "example-". $ rs [$ I] [name];
}
Else
{
$ Name. = "example-". $ rs [$ I] [name];
}
If ($ rs [$ I] [isdir])
{
$ Str. = "". $ name ."";
}
Else
{
$ Str. = $ name ";
}
$ Temp = $ count 1;
$ Str = $ this-> sort_list ($ str, $ rs [$ I] [id], $ temp );
$ I;
}
Return $ str;
}
$ This-> The SQL object is an SQL operation object, the re_datas () function returns the queried array, and the SQL _numrows () function returns the queried number.
Call method: $ sort_list = sort_list ($ sort_list, 0, 1 );
The above are my personal thoughts. I hope you can give more advice. By 5 W desk lamp