天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

PHP無(wú)限分類的類

復(fù)制代碼 代碼如下:
<?php
/**
 * @author        YangHuan
 * @datetime    
 * @version        1.0.0
 */

/**
 * Short description.
 *
 * Detail description
 * @author       
 * @version      1.0
 * @copyright    
 * @access       public
 */
class Tree
{
    /**
     * Description
     * @var       
     * @since     1.0
     * @access    private
     */
    var $data    = array();

    /**
     * Description
     * @var       
     * @since     1.0
     * @access    private
     */
    var $child    = array(-1=>array());

    /**
     * Description
     * @var       
     * @since     1.0
     * @access    private
     */
    var $layer    = array(-1=>-1);

    /**
     * Description
     * @var       
     * @since     1.0
     * @access    private
     */
    var $parent    = array();

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function Tree ($value)
    {
        $this->setNode(0, -1, $value);
    } // end func

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function setNode ($id, $parent, $value)
    {
        $parent = $parent?$parent:0;

        $this->data[$id]            = $value;
        $this->child[$id]            = array();
        $this->child[$parent][]        = $id;
        $this->parent[$id]            = $parent;

        if (!isset($this->layer[$parent]))
        {
            $this->layer[$id] = 0;
        }
        else
        {
            $this->layer[$id] = $this->layer[$parent] + 1;
        }
    } // end func

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none 
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function getList (&$tree, $root= 0)
    {
        foreach ($this->child[$root] as $key=>$id)
        {
            $tree[] = $id;

            if ($this->child[$id]) $this->getList($tree, $id);
        }
    } // end func

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function getValue ($id)
    {
        return $this->data[$id];
    } // end func

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function getLayer ($id, $space = false)
    {
        return $space?str_repeat($space, $this->layer[$id]):$this->layer[$id];
    } // end func

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function getParent ($id)
    {
        return $this->parent[$id];
    } // end func

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function getParents ($id)
    {
        while ($this->parent[$id] != -1)
        {
            $id = $parent[$this->layer[$id]] = $this->parent[$id];
        }

        ksort($parent);
        reset($parent);

        return $parent;
    } // end func

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function getChild ($id)
    {
        return $this->child[$id];
    } // end func

    
    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function getChilds ($id = 0)
    {
        $child = array($id);
        $this->getList($child, $id);

        return $child;
    } // end func
} // end class

?>

使用方法

php代碼:

復(fù)制代碼 代碼如下:
<?php
//new Tree(根目錄的名字);
//根目錄的ID自動(dòng)分配為0
$Tree = new Tree('根目錄');

//setNode(目錄ID,上級(jí)ID,目錄名字);
$Tree->setNode(1, 0, '目錄1');
$Tree->setNode(2, 0, '目錄2');
$Tree->setNode(3, 0, '目錄3');
$Tree->setNode(4, 3, '目錄3.1');
$Tree->setNode(5, 3, '目錄3.2');
$Tree->setNode(6, 3, '目錄3.3');
$Tree->setNode(7, 2, '目錄2.1');
$Tree->setNode(8, 2, '目錄2.2');
$Tree->setNode(9, 2, '目錄2.3');
$Tree->setNode(10, 6, '目錄3.3.1');
$Tree->setNode(11, 6, '目錄3.3.2');
$Tree->setNode(12, 6, '目錄3.3.3');

//getChilds(指定目錄ID);
//取得指定目錄下級(jí)目錄.如果沒(méi)有指定目錄就由根目錄開(kāi)始
$category = $Tree->getChilds();

//遍歷輸出
foreach ($category as $key=>$id)
{
    echo $Tree->getLayer($id, '|-').$Tree->getValue($id)."<br>/n";
}

php無(wú)限分類-php100代碼

復(fù)制代碼 代碼如下:
<?php
//無(wú)限分類,從子類找所有父類
//$id 子類ID
 function php100_xd($id){
   $sql="select * from fl where id='$id'";
   $q=mysql_query($sql);
   $rs=mysql_fetch_array($q);
   $rs['fid']==0 ? "" : fl($rs['fid']);
   echo $rs['name']."-";
   }

//讀取所有父類下面的子類
//$f頂級(jí)分類從什么開(kāi)始,$s樣式
 function php100_dx($f=0,$s=""){
   $sql="select * from fl where fid=$f";
   $q=mysql_query($sql);
   $s=$s."-";
   while($rs=mysql_fetch_array($q)){
     echo "<br>$s".$rs['name'];
  flt($rs['id'],$s);
     }
   }

php技術(shù)PHP無(wú)限分類的類,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 青柠视频在线观看高清HD | 老年日本老年daddy | 在线观看插女生免费版 | 邪恶肉肉全彩色无遮琉璃神社 | 国产成人理在线观看视频 | 亚洲人成人毛片无遮挡 | 亚洲一区乱码电影在线 | 521人成a天堂v | 热综合一本伊人久久精品 | 久久久久毛片免费观看 | 国产精品香蕉视频在线 | 国内久经典AAAAA片 | 日久精品不卡一区二区 | 日韩内射美女人妻一区二区三区 | yellow在线观看免费高清的日本 | 让人爽到湿的小黄书 | 奶好大下面流了好多水水 | 国内精品久久久久久久999下 | 孕妇高潮抽搐喷水30分钟 | 在线免费观看a视频 | 亚洲国产成人爱AV在线播放丿 | 久久re这里视频只有精品首页 | 冈本视频黄页正版 | 九九热这里都是精品 | 国产欧美一区二区精品性色tv | 果冻传媒在线观看完整版免费 | 伊人国产在线视频 | 久青草国产在线视频 | 国产高清国内精品福利色噜噜 | 灰原哀被啪漫画禁漫 | tube日本护士 | 免费韩国伦理2017最新 | 伊人久久大香线蕉电影院 | 4480yy午夜私人影院 | 久久精品男人影院 | 国产亚洲精品久久久久 | 亚洲AV久久无码精品热九九 | 日本高清无人区影院 | 午夜免费啪视频观看视频 | 国外经典三级 | 且试天下芒果免费观看 |