Php multi-level navigation display write once, want to do it again ...? This is now .. in the future, use the copy directly. the first code shows the category to be displayed. put the first-level directory in categories [0], the second-level directory in categories [1], and the third-level directory in categories [2],... and so on. generally, it is no longer divided into three levels. $ cpatharray (php multi-level navigation display
Write it once and try again ...? This is where it is. we will copy it directly later.
The first code
The category to be displayed.
Put the first-level directory in categories [0],
The level-2 directory is placed in categories [1],
Put the third-level directory in categories [2],
... And so on
However, generally, no further score can be obtained at most three levels.
$cpath = array();if(!empty($_REQUEST["parentId"])){//category path//get the category path//put current category id in $cpath$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 code is
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);
?
?