PHP Multilevel Navigation display
Write once, think once ... Do it again ...? Here we go. Come directly to copy later.
First paragraph of code
Gets the category to display.
The first level directory is placed in Categories[0],
The secondary catalogue is placed in categories[1],
Level Three directory is placed in categories[2],
.... And so on
However, generally up to level 3 will not be divided down.
$cpath = Array (), if (!empty ($_request["ParentID")) {//category Path//get the category path//put current category ID in $CP ath$current_category["ParentID"] = $_request["ParentID"];//put parent category ID in $cpath do{array_unshift ($cpath, $ current_category["ParentID"]); $data _category = array ("id" = = $current _category["ParentID"]); $current _category = Array (); $current _category = pos ($db _conn->search ($db _category, $data _category));} while (!empty ($current _category["ParentID"));} Add the first level category Parentidarray_unshift ($cpath, "null");//Get all Categories$categories_level_count = sizeof ($cpath), for ($i =0; $i $cpath [$i]),//get first level categories$categories[$i] = $db _conn->search ($db _ Category, $data _category);//echo $db _category->search ($data _category). "";
The second piece of code is to set the menu to
The form of the display menu
function Show_left_navigation ($i) {global $categories, $cpath; if (Empty ($categories [$i])) Return;echo '
'; foreach ($categories [$i] as $id = + $category) {echo '; if ($id ==end ($cpath)) echo '. $category ["name"]. "; Elseecho '. $category ["name"]. "; if (In_array ($id, $cpath)) show_left_navigation ($i + 1); echo ';} Echo '
; }show_left_navigation (0);
?
?