Infinite class classification, mainly by storing the ID of the parent classification and the classification path to achieve. Since the structure of the data is simple, I can only think of the recursive way to show the relationship of the classification to the tree.
Infinite class classification, mainly by storing the ID of the parent classification and the classification path to achieve. Because the structure of the data is simple, so the relationship between the classification of the tree display, I can only think of the recursive way to achieve, the following is the structure of the classification data table and a tree-like display function, what is wrong with the place I hope you can point out.
Table structure: The ID field is the category identification, the Name field is the category name, the father_id field is the Id,path field of the parent category that belongs to the taxonomy path (the collection that stores the ancestor of that category), Isdir determines whether it is a directory (1 is yes, 0 is no).
Display function:
Copy the Code code as follows:
$count as 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. = "└─". $rs [$i][name];
}
Else
{
$name. = "├─". $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;
}
Where the $this->sql object is the SQL Action class object, the Re_datas () function returns the array that is found, and the Sql_numrows () function returns the number of queries to
Calling method: $sort _list = sort_list ($sort _list,0,1);
The above for personal thinking, but also hope that we have a lot of guidance
The above describes the infinite pole seven-core water purifier Php+mysql to achieve unlimited class classification | The tree type displays the classification relation, including the infinite pole seven core level water purifier aspect content, hoped to be interested in the PHP tutorial friend to be helpful.