Introduction: This is an infinitely classified PHP MySQL implementation. | a detailed page for displaying classification relationships in a tree type describes PHP, related knowledge, skills, experiences, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 323996 'rolling = 'no'>
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 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. = "<span style = 'color: # cccccc'>". $ name. "</span> ";
}
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
Love J2EE follow Java Michael Jackson video station JSON online tools
http://biancheng.dnbcw.info/php/323996.html pageno: 15