天天躁日日躁狠狠躁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)系我們修改或刪除,多謝。

主站蜘蛛池模板: 亚洲国产精品一区二区第一页 | 妻中蜜在线播放 | 一个人免费视频在线观看高清版 | 久草热8精品视频在线观看 久草青青在线 | 91精品一区二区综合在线 | 女人被躁到高潮嗷嗷叫小 | 国产不卡一卡2卡三卡4卡网站 | 欧美精品亚洲精品日韩专区一 | 热久久免费频精品99热 | 97人妻中文字幕免费视频 | 国产精品无码久久久久不卡 | 琪琪的色原网站 | 成人国产精品玖玖热色欲 | 三男强一女90分钟在线观看 | 国产成人cao在线 | 二次元美女扒开内裤喷水 | 亚洲视频区 | 一本道mw高清码二区三区 | 国产亚洲精品久久精品69 | 亚洲 无码 在线 专区 | 国产成人无码免费精品果冻传媒 | 久久精品热线免费 | 黑人猛挺进小莹的体内视频 | 亚洲不卡一卡2卡三卡4卡5卡 | 91欧美秘密入口 | 国产真实露脸乱子伦 | 内射少妇36P亚洲区 内射少妇36P九色 | 秋霞电影院兔费理论观频84mb | 久久久久久极精品久久久 | 影音先锋av色咪影院 | 精品久久伊人 | 99热这里只有 精品 99热这里只就有精品22 | 玄幻全黄h全肉后宫 | 两性色午夜视频免费国产 | 村上里沙快播 | Y8848高清私人影院软件优势 | 欧美日韩午夜群交多人轮换 | 亚洲成人在线免费观看 | 视频一区亚洲中文字幕 | 在线自拍综合亚洲欧美 | 97超碰射射射 |