Infinitus classification is generally used for product or site product classification. Let's take a look at the algorithms and code for using recursive methods. Infinitus classification is generally used for product or site product classification. Let's take a look at the algorithms and code for using recursive methods.
Script ec (2); script
// $ Parent is the parent of the children we want to see
// $ Level is increased when we go deeper into the tree,
// Used to display a nice indented tree
Function display_children ($ parent, $ level ){
// Obtain all child nodes of a parent node $ parent
$ Result = mysql_query ("
SELECT name
FROM tree
WHERE parent = '". $ parent ."'
;"
);
// Display each subnode
While ($ row = mysql_fetch_array ($ result )){
// Display the node name in indentation
Echo str_repeat ('', $ level). $ row ['name']." n ";
// Call this function again to display the subnode of the subnode
Display_children ($ row ['name'], $ level + 1 );
}
}
?>
Use this function for the root node (Food) of the entire structure to print the entire multi-level tree structure. Because Food is the root node, its parent node is empty, so we call it like this: display_children ('', 0 ). The contents of the entire tree are displayed: Food
Fruit
Red
Cherry
Yellow
Banana
Meat
Beef
Pork