中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

php 無限級 SelectTree 類

復制代碼 代碼如下:
/*
author: nick
date: 2009.05.17
功能:生成SeletTree
屬性:
$result 結果集
$id_field 自身id字段
$parent_field 父類id字段
$option_text 選項顯示名稱
$select_name 下拉菜單的名稱
$elected 默認選中
$no_top 是否需要頂層選項
$level 層深度
$parent_id 同層中的id
*/
class SelectTree{
public $result;
public $select_name;
public $option_text;
public $elected;
public $id_field;
public $parent_field;
public $no_top;
public $level;
public $parent_id;
public $getarray;
function __construct($result,$id_field,$parent_field,$option_text,$select_name='',$elected=0,$no_top=0,$level=0,$parent_id=0){
$this->result =$result;
$this->id_field =$id_field;
$this->parent_field =$parent_field;
$this->option_text =$option_text;
$this->select_name =$select_name;
$this->elected =$elected;
$this->no_top =$no_top;
$this->level =$level;
$this->parent_id =$parent_id;
$this->getarray =self::getArray();
}
/*
功能:返回Tree二維數組
*/
function getArray(){
$arrays=array();
while($row=mysql_fetch_array($this->result)){
$arrays[$row[$this->parent_field]][$row[$this->id_field]]=$row;
}
return $arrays;
}
/*
功能:獲取SelectTree
*/
function getSelectTree(){
$tree = '<select name="'.$this->select_name.'">';
if($no_top){
$tree .= '<option value="0">最頂層</option>';
}
self::buildTree($this->getarray,&$tree,$this->id_field,$this->option_text,$this->selected,$this->level,$this->parent_id); //生成樹狀結構
$tree .= '</select>';
return $tree;
}
/*
功能:遞歸構建樹狀結構
*/
function buildTree($array,&$tree,$option_value,$option_text,$selected,$level=0,$parent_id=0){
if(is_array($array[$parent_id])){
for($i=0;$i<$level;$i++)
$space .= ' '; //選項縮進深度
foreach($array[$parent_id] as $key => $value){
if($value[$option_value] == $selected){
$tree .= '<option value="'.$value[$option_value].'" selected="selected">'.$space.$value[$option_text]."</option>";
}else{
$tree .= '<option value="'.$value[$option_value].'">'.$space.$value[$option_text]."</option>";
}
$tree .=self::buildTree($array,&$tree,$option_value,$option_text,$selected,$level+1,$key);
}
}else{
$tree .= '';
}
}
}
/****************************************************************************/
header("CONTENT-TYPE:TEXT/HTML;CHARSET=UTF-8");
mysql_connect("localhost","root","root");
mysql_select_db("tree");
mysql_query('set names utf8');
$result = mysql_query("select * from tvmenu");
$tree=new SelectTree($result,'id','bid','name','tree');
echo $tree->getSelectTree();

php技術php 無限級 SelectTree 類,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 91精品综合久久久久久五月天 | 91免费看片| 日本在线中文 | av中文字幕在线 | 日日做夜夜爽毛片麻豆 | 在线91| 一区二区三区小视频 | 色综合视频 | 热99| 欧美精品中文字幕久久二区 | 精品久久久久久亚洲综合网 | 精品久久久一区 | 国产成人高清在线观看 | 免费在线一区二区三区 | 国产精品日女人 | 羞羞涩涩在线观看 | 欧美1区2区 | 午夜国产 | 日韩中文在线 | 91精品久久久久久久久中文字幕 | 不卡在线视频 | 一区二区三区在线观看视频 | 污视频免费在线观看 | 一级在线| 美女久久| 欧美xxxx色视频在线观看免费 | 久久国产精品网 | 正在播放国产精品 | 精品国产黄a∨片高清在线 www.一级片 国产欧美日韩综合精品一区二区 | 干干干操操操 | 天天成人综合网 | 国产精品资源在线 | 国内久久| 日韩精品在线免费观看 | 精品福利视频一区二区三区 | 青青草久久 | 亚洲精品视频在线看 | 我我色综合 | 天天综合永久入口 | 免费看黄色国产 | 中文字幕亚洲精品 |