php 多級領航顯示

來源:互聯網
上載者:User
php 多級導航顯示

寫一次,想一次...重新做一次...? 這回就放這了..以後用直接過來copy.

第一段代碼

得到要顯示的類別.

一級目錄放在categories[0],

二級目錄放在categories[1],

三級目錄放在categories[2],

....以此類推

不過一般最多到3級就不再往下分了.

$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)."";}





第二段代碼是將菜單以

    ?
    • ...
    ?



的形式顯示菜單

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);

?

?

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.