PHP Multilevel Navigator Display

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

?

?

  • 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.