提供各種蟲害防治諮詢、專營居家環境消毒清潔
除蟲消毒一通電話服務到家
台北油漆粉刷專業廢棄物清運、大型廢棄家具,政府立案
正派經營,作業快速、合法可靠

首頁  •  tw 論壇 • 程式設計討論     • 

TREE_MENU樹狀選單

房東:小翰
發表時間:2006-12-26
[檢舉]

<\" . $celltype . \">\";
if ($url == \"\") {
if ($fragment == \"\") {$output .= $desp;}
else {$output .= $fragment($subid);} // always pass the subid just in case we want it.
}
else {
// got to be sneaky with the quote marks here to acheive my goal.
$output .= \" if ($dest == \"frame\") { $output .= \'javascript:dolink(\"\' . $this->id .\'\",\"\' . $subid .\'\",\"\' . $url . \'\")\' . \"\'>\";} // $dest = frame
elseif ($dest == \"self\"){$output .= $url . \"\' target=\'_self\'>\";}
else {$output .= \'javascript:doextlink(\"\' . $this->id . \'\",\"\' . $subid . \'\",\"\' . $url . \'\"\' . \")\'>\";}
$output .= $desp . \"
\";
} // url=\"\"
$output .= \'\' . \"n\";
return $output;
} // buildURL
} // submenu class

class menu { /* The main class */

var $submenus; // array of submenu information
var $cot = 0; // count
var $id; // id column?
var $subid; // pointer to the submenu
var $autoclose; // add the tags to the code?

function menu ($id = 2, $subid = -1, $autoclose = \"Auto\") { // constructor
$this->id = $id;
$this->subid = $subid;
$this->autoclose = $autoclose;
} // constructor

function add($submenu) { /* link the submenu to the parent */
$this->submenus$$this->cot]=new submenu;
$this->submenus$$this->cot]=$submenu;
$this->cot++;
} // add

function getHeader() {
/* Everything you want to go above the menu. This would probably be best as an included
html fragment, put in here to allow an example. Few more styles than needed for this example. Remove as necessary.
*/
?>



Residential Property Investor magazine - Menu





} // getHeader

function show() { /* Public Function */
$i=0;
$this->getHeader();
$tmp = new submenu;
echo \'

/*
** 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 = \"
\';
while ($i<$this->cot) {
$tmp=$this->submenus$$i];
if ($tmp->id == (string)$this->id) { $tmp->open($this->subid); }
else { $tmp->closed(); }
$i++;
} // while
echo \'
\';
if ($this->autoclose == \"Auto\"){echo \"\";}
}// show

} // End of Class definition

function issuelist($subid=0) { // separate from the classes
//$title = \"Back Issues\";
//if ($subid == 3) {$title = strtoupper($title);}
$output = \'
Back Issues
\';
return $output;
}

// From here is the real code which we call.

$sm_1=new submenu(\"1\");
$sm_1->add(\'../rpimag/home.htm\',\'Home\');

$sm_2=new submenu(\"2\");
$sm_2->add(\'\',\'Issues\',\'self\');

$sm_3=new submenu(\"3\");
$sm_3->add(\'\',\'Links\',\'self\');

$sm_4=new submenu(\"4\");
$sm_4->add(\'\',\'Can We Help?\',\'self\');

$sm_5=new submenu(\"5\");
$sm_5->add(\'\',\'Free Stuff\',\'self\');

$sm_6=new submenu(\"6\");
$sm_6->add(\'http://www.pcpropertymanager.com\',\'PC Property Manager\',\'new\');


switch ($id){
case 2:
// we calculate this month so would need to do this here.
$sm_2->add(\'../rpimag/issues/issue.php?show=current\',\'Current Issue\');
$sm_2->add(\'../rpimag/backtop.htm\',\'Back Issues by Topic\');
$sm_2->add(\'\',\'Back Issues\',\'frame\',\'issuelist\');

case 3:
$sm_3->add(\'../rpimag/linklist.htm#PropLinks\',\'Property Links\');
$sm_3->add(\'../rpimag/linklist.htm#Lending\',\'Lending Institutions\');
$sm_3->add(\'../rpimag/linklist.htm#PIA\',\'NZ Property Investor Assns\');
$sm_3->add(\'../rpimag/linklist.htm#AusPIA\',\'Australian PIAs\');

case 4:
$sm_4->add(\'../rpimag/contacts.htm#letters\',\'Letters\');
$sm_4->add(\'../rpimag/contacts.htm#letters\',\'Get Expert Help\');
$sm_4->add(\'../rpimag/contacts.htm\',\'Contact Details\');

case 5:
$sm_5->add(\'../rpimag/docs.htm\',\'Documents\');
$sm_5->add(\'../rpimag/research.htm\',\'Rental Statistics\');
$sm_5->add(\'../rpimag/research.htm\',\'Newsletter\');
$sm_5->add(\'../rpimag/subsform.htm\',\'Subscriptions\');
}

$m_1=new menu($id, $subid, \"Manual\");
$m_1->add($sm_1);
$m_1->add($sm_2);
$m_1->add($sm_3);
$m_1->add($sm_4);
$m_1->add($sm_5);
$m_1->add($sm_6);

$m_1->show();

?>




  • 贊助網站       

    廣利不動產-新板特區指名度最高、值得您信賴的好房仲
    您的托付,廣利用心為您服務
    廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲
    完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心!

  • 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:


    用php製作樹狀選單




    include("connection.php");//連結資料庫
    makeTreeNode(0);
    function makeTreeNode($id){
    $rs=mysql_query("select * from menu where parent=$id");
    echo "
      \n";
      while(list($id,$name,$url,$target,$parent)=mysql_fetch_array($rs)){
      echo "
    • $name
    • \n";
      echo "
      \n";
      makeTreeNode($id);
      echo "
      \n";
      }
      echo "
    \n";
    }
    ?>








     共 1 人回應  選擇頁數 【第1 頁】 

    姓名:
    佈告內容: