Php multi-level pilot display

Source: Internet
Author: User
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);

?

?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.