<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      無限級別菜單的完成

      [摘要]<? /* 看到很多朋友問過無限級別菜單的的問題(其實理論上還是有級別的,畢竟要受到個方便的條件的限制,比如: 數據庫字段的類型等),我曾經用老大(嘮叨)提供的代碼寫出來過無限級別的菜單,但是感覺效果不是很好(視覺上),于是趁著"夜深人靜"就寫這個"無限制級別...
      <?  /* 看到很多朋友問過無限級別菜單的的問題(其實理論上還是有級別的,畢竟要受到個方便的條件的限制,比如: 數據庫字段的類型等),我曾經用老大(嘮叨)提供的代碼寫出來過無限級別的菜單,但是感覺效果不是很好(視覺上),于是趁著"夜深人靜"就寫這個"無限制級別的菜單",其實道理很簡單,主要是數據表的設計,還有遞歸方法的使用(如果有時間我會用中值排序法來做),我會在下面給出數據結構的設計(非常簡單),這里我沒有加上豎直的虛線(windows資源管理器的虛線),同時Sql語句我也將其固定,大家可以根據自己的需要來修改!如果有問題可以聯系我:msn:banneryue@sina.com,QQ:7665656,E_mail:yuepengfei@mail.banner.com.cn

      明天(已經是今天了,呵呵)我會提供一個測試頁面讓大家來看(因為我在宿舍只能撥號上網,Ip地址不固定)

      */

      /** 遞歸顯示子節點函數
      *
      *
      * @param $SearchPattern    查找的條件(like)
      * @param $BaseNum 節點的層數
      */

                 function ListChildTree($SearchPattern,$BaseNum){
                     global $Tree;//聲明連接數據庫的句柄為全局
                     $Sql="select DepartmentId,DepartmentName from test where DepartmentId like '$SearchPattern'";    //查找孩子節點
                     $QueryChild=$Tree->query($Sql);          
                     while($Result=$Tree->fetch_array($QueryChild)) { //取出孩子節點
                         $Space="";
                          for($j=0;$j<((strlen($SearchPattern)/3)-$BaseNum);$j++)
                            $Space.="  ";                 //設置顯示節點前面的距離,這里的空格的html被這里自動替換成"  "了
                         $ChildDepartment=trim($Result[0])."___";            
                         $ChildSql="select count(*) from test where DepartmentId like '$ChildDepartment'";//查找孩子節點的孩子節點
                         $ChildResult=$Tree->query_first($ChildSql);             
                         $TableId="ta".trim($Result[0]); //設置表格Id
                         $TablePic="ta".trim($Result[0])."pic";    //設置圖片Id                   
                         if($ChildResult[0]<1){//如果沒有找到孩子節點的節點,則顯示"-"圖片
                            ?>
                          <tr><td><?=$Space?><span align="absmiddle"><img src=http://www.okasp.com/techinfo/"leaf.gif" border="0" align="absmiddle" width="35" height="17"></span><font size="2"><A href="process.php?SearchPattern=<?=trim($Result[0])?>" class="F1"><?=$Result[1]?></a></font>
                          <table id="<?=$TableId?>" style="display=none" cellspacing="0" cellpadding="0">
                      
                       <?}else{           //找到則顯示"+"圖片            
                        ?>
                         <tr><td><?=$Space?><a onclick="javascript:expands('<?=$TableId?>','<?=$TablePic?>')" style="cursor:hand"><span align="absmiddle"><img id="<?=$TablePic?>" src=http://www.okasp.com/techinfo/"parent.gif" border="0" align="absmiddle" width="35" height="17"></span></a><font size="2"><A href="process.php?SearchPattern=<?=trim($Result[0])?>" class="F1"><?=$Result[1]?></a></font>
                        <table id="<?=$TableId?>" style="display=none" cellspacing="0" cellpadding="0">
                  <?
                    ListChildTree($ChildDepartment,$BaseNum);//遞歸調用函數本身來顯示其他孩子節點
                  }//end if?>
                   </table>
                  <?}//end while
                 }//end function?>
      <html>
      <head>
      <title>無限級菜單測試</title>
      <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
      <link rel="stylesheet" href="../text.css" type="text/css">
      <script language="javascript">
      function expands(expid,picid) //顯示圖片張合的Js
      {   //    alert("this.document.all["+expid+"].style.display");
        if(this.document.all[expid].style.display=="none")
        { this.document.all[expid].style.display="block";
          this.document.all[picid].src=http://www.okasp.com/techinfo/"leaf.gif";

        }
        else
        {
          this.document.all[expid].style.display="none";
          this.document.all[picid].src=http://www.okasp.com/techinfo/"parent.gif";
        }
      }
      </script>
      </head>

      <body bgcolor="#FFFFFF" text="#000000">
      <?
        require("do_mySql.php");
      $Tree = new DB_Sql;
      $Tree->connect();//連接數據庫,可根據需要換成自己的代碼

        $Sql="select DepartmentId,DepartmentName from test where length(DepartmentId)=3";//提出最上層節點(祖宗節點),根據需要自己修改
        $Result=$Tree->query_first($Sql);
      ?>
      <div align="center">                         
        <center>                         
        <table border="1" cellpadding="0" cellspacing="0" width="766" bordercolor="#DDCF90" height="392">                         
          <tr>                         
            <td valign="top">                     
              <div align="center">         
                <table border="0" cellpadding="0" cellspacing="0" width="372">         
                  <tr>         
                    <td width="368"><a onclick="javascript:expands('dwtop','dwimg')" style="cursor:hand"><span align="absmiddle"> <img id="dwimg" SRC=http://www.okasp.com/techinfo/"parent.gif" border="0" align="absmiddle" width="35" height="17"></span></a><font size="2"><a href="process.php?SearchPattern=<?=$Result[0]?>"><?=$Result[1]?></a></font>                                                                                      
              <table id="dwtop" style="display=none" cellspacing="0" cellpadding="0">
               <?        
                     $FirstDepartment=$Result[0];
                     $BaseNum=strlen($FirstDepartment)/3;//計算層數,其實這個有點多余,因為其必為第一層
                     $SearchPattern=$FirstDepartment."___";    //設置查找條件       
                     ListChildTree($SearchPattern,$BaseNum);        //顯示祖宗節點的孩子節點
               ?>
              </table>
              </td>
               </tr>
              </table>
             </div>
            </td>
           </tr>
          </table>
             </center>
         </div>

      </body>
      </html>

      <?/* 表結構的設計

      由于是測試表設計得非常的簡單:

      CREATE TABLE test (
        id mediumint(8) unsigned NOT NULL auto_increment, #流水號
        DepartmentId varchar(100) NOT NULL default '',    #單位代號
        DepartmentName varchar(100) NOT NULL default '',  #單位名稱
        KEY id (id)  
      )

      數據插入的代碼我在這里就不那出來給大家了(很容易寫,相信大家都能寫出來)

      數據表的規則為:

      001為第一級(如果999個不夠,請自行添加)
      001001為001的第一個子節點,001002為001的第二個子節點
      001001001為001001的第一個子節點,以此類推……

      我這里只設置了一個"祖宗"(001),所以在程序中就直接調用了,可根據需要自己來設置,并對代碼作簡單的修改即可!

      好了,就到這里了,如果大家有問題歡迎和我探討!最好祝大家今天工作愉快!
      先吸顆煙在睡覺!好累。ㄒ驗閯倓倢懥艘粋webFtp,如果哪位兄弟姐妹需要請mail我)
      */


      ?>




      日韩精品一区二区三区高清