專業居家清潔 免費到府估價,清潔養護馬上搞定 | 一張保單輕鬆享有人生各階段風險保障 通通幫您規畫好 |
TREE_MENU樹狀選單 |
房東:小翰 發表時間:2006-12-26 |
/* ** treemenu.php class version 1.0 12/24/99 [email protected] ** version 1.2 04/15/01 [email protected] ** version 1.3 04/22/01 [email protected] */ /******************************************************* * This is based on v1.0. Thanks for original code. * v1.2 adds the ability to have a more customised look of each * cell. I'd probably use styles to control the standard look and * just pass the exceptions. Worth considering incorporating the here. * * My Changes: * 1. Handles frames by using javascript. Change the frame names in the * two javascript functions to your own frames and change the urls to * some of your own and it should start working. * 2. Handles menus's without submenus. We have significant pages which needed * their own bar but didn't have any other options. * 3. Handles links to external and internal pages * 4. Added constructors to simply code * 5. Controls appearance through styles * 6. Makes selected items upper case, other effects may be applied. * SubId tracks the submenu selected so that it can be highlighted. * I've just used uppercase to highlight. * 7. Dropped the $action parameter. It wasn't being used. * 8. Added AutoClose to the menu parameters, allows you to keep the page * open to add other functionality * 9. Added a concept which started life being called fragments but which * really just calls a separate function to allow something quite different * to be used. In this example a cut down list of the magazine issues we * have produced. The function returns the html. Have tried to limit the * use of echo to a few strategic places. * * FINALLY as a php newbie it's been a really interesting experience getting * this code and playing with it. ********************************************************/ class submenu { var $urls; // url var $desps; // description var $dests; // destinations var $cot = 0; // count var $id; // id of the new menu, ie submenu 3 function submenu($id = 1) { // Constructor. Creates the new submenu $this->id = $id; }// constructor function add($url, $desp, $dest="frame", $fragments="") { $this->urls$$this->cot]=$url; $this->desps$$this->cot]=$desp; $this->dests$$this->cot]=$dest; $this->fragments$$this->cot]=$fragments; $this->cot++; } // add function open($subid = -1) { // selected menu option $i=0; if ( $subid > 0) { $this->desps$$subid] = strtoupper($this->desps$$subid]);} while($i <= $this->cot) { if ($i==0) { // Menu Heading $newUrl = $this->giveUrl(); echo $this->buildURL( $i, strtoupper ($this->desps$0]), $newUrl, $this->dests$$i],$this->fragments$$i],'th'); } else { // submenus echo $this->buildURL($i, $this->desps$$i], $this->urls$$i], $this->dests$$i],$this->fragments$$i]); } $i++; } // while ($i<=$this->cot) } // open function closed() { /* don't show the submenu, just the banner */ $newUrl = $this->giveUrl(); echo $this->buildURL(0, $this->desps$0], $newUrl, $this->dests$0],$this->fragments$0],'th'); } // closed function giveUrl() { if ($this->urls$0] == ""){$retUrl = "?id=" . $this->id . "&subid=0";} else {$retUrl = $this->urls$0];} return $retUrl; } function buildURL($subid, $desp, $url="", $dest="", $fragment="", $celltype="td") { // Works for all options?, receives the parameters and goes from there. $output = " |
|
廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲 完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心! 廣利不動產-新板特區指名度最高、值得您信賴的好房仲 您的托付,廣利用心為您服務 |
1 樓住戶:妹子 發表時間:2007-01-19 |
--首先請用phpmyadmin把以下資料貼進去資料庫裡以建立一資料表叫menu -- phpMyAdmin SQL Dump -- version 2.6.0-rc1 -- http://www.phpmyadmin.net -- -- 主機: localhost -- 建立日期: Dec 25, 2004, 11:16 PM -- 伺服器版本: 4.0.20 -- PHP 版本: 5.0.1 -- -- 資料庫: `test` -- -- -------------------------------------------------------- -- -- 資料表格式: `menu` -- --id為流水號 --name為每個樹節點的名稱 --url為超連結 --target為目標框架頁 --parent為父節點,若為0則無父節點 -- CREATE TABLE `menu` ( `id` int(10) unsigned NOT NULL auto_increment, `name` varchar(50) NOT NULL default '', `url` varchar(50) NOT NULL default '', `target` varchar(50) NOT NULL default '', `parent` int(11) NOT NULL default '0', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=11 ; -- -- 列出以下資料庫的數據: `menu` -- INSERT INTO `menu` VALUES (1, '搜尋器', '#', '_self', 0); INSERT INTO `menu` VALUES (2, 'php網站', '#', '_self', 0); INSERT INTO `menu` VALUES (3, 'kimo', 'http://www.kimo.com.tw', '_blank', 1); INSERT INTO `menu` VALUES (4, 'google', 'http://www.google.com', '_blank', 1); INSERT INTO `menu` VALUES (5, '國內', '#', '_self', 2); INSERT INTO `menu` VALUES (6, '國外', '#', '_self', 2); INSERT INTO `menu` VALUES (7, 'php5討論區', 'http://www.php5.idv.tw', '_blank', 5); INSERT INTO `menu` VALUES (8, 'twbb討論區', 'http://www.twbb.org/forum/', '_blank', 5); INSERT INTO `menu` VALUES (9, 'php.net', 'http://www.php.net', '_blank', 6); INSERT INTO `menu` VALUES (10, 'zend', 'http://www.zend.com/', '_blank', 6); 其次,撰寫主要程式碼如下: [Copy to clipboard]CODE: include("connection.php");//連結資料庫 makeTreeNode(0); function makeTreeNode($id){ $rs=mysql_query("select * from menu where parent=$id"); echo "
while(list($id,$name,$url,$target,$parent)=mysql_fetch_array($rs)){ echo " echo " \n"; } echo " } ?> |
姓名: | |||
佈告內容: | |||
其他選項: | |||
|