ʹÓú¯ÊýµÝ¹éʵÏÖ»ùÓÚphpºÍMySQLµÄ¶¯Ì¬Ê÷ÐͲ˵¥

5年以前  |  阅读数:756 次  |  编程语言:PHP 
Ê÷ÐͲ˵¥Ôںܶa×ÀÃaeÓ¦ÓÃϵͳÖж¼ÓÐ*dz£¹a*ºµÄÓ¦Óã¬ÆaÖ÷ÒªÓŵaÊǽa¹¹ÇaÎu£¬ÀuÓÚʹÓÃÕß*dz£Ça³þµÄÖªµÀÄ¿Ç°×Ô¼ºËuÔÚµÄλÖᣵ«ÔÚwebÉÏÊ÷ÐͲ˵¥µÄÓ¦ÓÃÒoΪûÓÐÀiÏeµÄÏÖ³É×e¼þ¿ÉÒÔÄùýÀ´Ö±½ÓʹÓã¬ËuÒÔÒ»°aµÄÇe¿oÏ£¬³ÌÐoÔ±Ö÷ÒªÊÇͨ¹ýJavaScriptÀ´ÊµÏÖÒ»Ð(C)¼oµ¥µÄÊ÷Ðͽa¹¹²Ëµ¥£¬µ«ÕaÐ(C)²Ëµ¥ÍuÍu¶¼ÊÇÊÂÏȶ¨ºÃ¸÷²Ëµ¥ÏiÄ¿£¬ÒÔ¼°¸÷²Ëµ¥ÏiÄ¿Ö®¼aµÄ²a´Î¹Øϵ£¬²»ÀuÓÚÀ(C)³a£¬Ò»µ(C)ÐeÒªÁiÒ»¸o²Ëµ¥½a¹¹Ê±£¬ÍuÍu»¹ÐeÒªÖØбaд£¬Òo´ËʹÓÃÆðÀ´²»ÊǺÜ*½±a¡£

¾­¹ý¶Ôº¯ÊýµÝ¹eµÄÑо¿£¬ÎÒ*¢ÏÖÕaÖÖÊ÷ÐͲ˵¥¿ÉÒÔͨ¹ýµÝ¹eº¯Êý£¬Ê¹Ê÷ÐͲ˵¥µÄÏÔʾʵÏÖ¶¯Ì¬±a»¯£¬²¢Ã»Óм¶ÊýµÄÏÞÖÆ¡£ÏÂÃae¾ÍÊÇÎÒÓÃphp,MySQL,JavaScriptдµÄÒ»¸o¶¯Ì¬Ê÷ÐͲ˵¥µÄ´¦Ài´uÂe£¬Èç¹u´o¼ÒÓÐÐËȤµÄ»°£¬¾ÍºÍÎÒÒ»ÆðÀ´¿´¿´ÎÒÊÇÈçºÎʵÏֵİɣº£(C)

Ê×ÏÈ£¬ÎÒÃÇÐeÒªÒ»¸oÊý¾Ý¿a£¬ÔÚÕa¸oÊý¾Ý¿aÖУ¬ÎÒÃǽ¨Á¢ÒÔÏÂÒ»Õűi£º

CREATE TABLE menu (
id tinyint(4) NOT NULL auto_increment,
parent_id tinyint(4) DEFAULT '0' NOT NULL,
name varchar(20),
url varchar(60),
PRIMARY KEY (id)
);

ÕaÕűiÖÐ
id ΪË÷Òý
parent_id ÓÃÀ´±£´aeÉÏÒ»¼¶²Ëµ¥µÄidºÅ£¬Èç¹uÊÇÒ»¼¶²Ëµ¥ÔoΪ0
name Ϊ²Ëµ¥µÄÃu³Æ£¬Ò²¾ÍÊÇÒªÔÚÒ³ÃaeÉÏÏÔʾµÄ²Ëµ¥ÄÚÈÝ
url Èç¹uij²Ëµ¥ÎªÄ(C)¼¶²Ëµ¥£¬ÔoÐeÒªÖ¸¶¨¸ÃÁ¬½ÓµÄurlµØÖ£¬Õa¸o×ֶξÍÊÇÓÃÀ´±£´ae´ËµØֵģ¬ÆaËu*ÇÄ(C)¼¶²Ëµ¥£¬¸Ã×Ö¶ÎΪ¿Õ

ºÃÁË£¬Êý¾Ý¿aÓÐÁË£¬Äa¾Í¿ÉÒÔÌi¼ÓÒ»Ð(C)¼Ç¼ÁË£¬ÏÂÃaeÊÇÎÒ×o²aÊÔµÄʱºo£¬Ê¹ÓõÄÒ»Ð(C)¼Ç¼£º

INSERT INTO menu VALUES ( '1', '0', 'ÈËʹÜÀi', '');
INSERT INTO menu VALUES ( '2', '0', 'ͨѶ½»Á÷', '');
INSERT INTO menu VALUES ( '3', '1', 'µµ°¸¹ÜÀi', '');
INSERT INTO menu VALUES ( '4', '1', '¿¼ÇÚ¹ÜÀi', 'http://localhost/personal/attendance.php');
INSERT INTO menu VALUES ( '5', '2', 'ͨѶ¼', '');
INSERT INTO menu VALUES ( '6', '2', 'ÍøÂç»aÒe', '');
INSERT INTO menu VALUES ( '7', '3', 'ÐÂÔoµµ°¸', 'http://localhost/personal/add_achive.php');
INSERT INTO menu VALUES ( '8', '3', '²eѯµµ°¸', 'http://localhost/personal/search_archive.php');
INSERT INTO menu VALUES ( '9', '3', 'ɾ³ýµµ°¸', 'http://localhost/personal/delete_archive.php');
INSERT INTO menu VALUES ( '10', '5', 'ÐÂÔoͨѶ¼Ç¼','http://localhost/communication/add_address.php');
INSERT INTO menu VALUES ( '11', '5', '²eѯͨѶ¼Ç¼', http://localhost/communication/search_address.php');
INSERT INTO menu VALUES ( '12', '5', 'ɾ³ýͨѶ¼Ç¼', http://localhost/communication/delete_address.php');
INSERT INTO menu VALUES ( '13', '6', 'ÕÙ¿ª»aÒe', 'http://localhost/communication/convence_meeting.php');
INSERT INTO menu VALUES ( '14', '6', '»aÒe²eѯ', 'http://localhost/communication/search_meeting.php');

ÔÚÌi¼Ó¼Ç¼µÄʱºo£¬Ò»¶¨Òª×¢Òa£¬ÇÒ»¼¶²Ëµ¥µÄparent_idÒ»¶¨ÒªÖ¸¶¨ÎªÉϼ¶²Ëµ¥µÄIDºÅ£¬ñÔoÄaµÄ²Ëµ¥ÊDz»»aÏÔʾ³oÀ´µÄ£º£(C)

ºÃÁË£¡ÓÐÁËÊý¾Ý¿a£¬ÏÂÃae¾ÍÊÇͨ¹ýphp,JavaScript°Ñ²Ëµ¥´ÓÊý¾Ý¿aÖжÁ³oÀ´£¬²¢ÏÔʾ³oÀ´ÁË£º£(C)

1¡¢JavaScript½Å±¾£º
function ShowMenu(MenuID)
{
if(MenuID.style.display=="none")
{
MenuID.style.display="";
}
else
{
MenuID.style.display="none";
}
}

Õa¸o½Å±¾ºÜ¼oµ¥£¬¾ÍÊÇÓÃÀ´ÏiÓ¦µa»÷ij¸o²Ëµ¥±»µa»÷µÄʼþµÄ¡£

2¡¢CSSÎļþ£º

TD {
FONT-FAMILY: "Verdana", "ËÎÌa"; FONT-SIZE: 12px; LINE-HEIGHT: 130%; letter-spacing:1px
}

A:link {
COLOR: #990000; FONT-FAMILY: "Verdana", "ËÎÌa"; FONT-SIZE: 12px; TEXT-DECORATION: none; letter-spacing:1px
}
A:visited {
COLOR: #990000; FONT-FAMILY: "Verdana", "ËÎÌa"; FONT-SIZE: 12px; TEXT-DECORATION: none; letter-spacing:1px
}
A:active {
COLOR: #990000; FONT-FAMILY: "Verdana", "ËÎÌa"; FONT-SIZE: 12px; TEXT-DECORATION: none; letter-spacing:1px
}
A:hover {
COLOR: #ff0000; FONT-FAMILY: "Verdana", "ËÎÌa"; FONT-SIZE: 12px; TEXT-DECORATION: underline; letter-spacing:1px
}

.Menu {
COLOR:#000000; FONT-FAMILY: "Verdana", "ËÎÌa"; FONT-SIZE: 12px; CURSOR: hand
}

¶¨ÒaÁËÒ»Ð(C)»u±¾µÄÑuʽÐÅÏ¢£¬±ÈÈç×ÖÌa£¬ÑÕÉ«£¬³¬¼¶Á¬½ÓµÄÑuʽµÈ£¬Èç¹uÄaÏe¸Ä±aÑuʽµÄ»°£¬Ö»ÒªÐÞ¸ÄÕaÀi¾ÍÐÐÁË£¡

3¡¢ÏÂÃae¾ÍÊÇÎÒµÄphpÒ³ÃaeÁË£¡

//Á¬½ÓÊý¾Ý¿a
$Con=mysql_connect("localhost","root","");
mysql_select_db("work");

//ÌaÈ¡Ò»¼¶²Ëµ¥
$sql="select * from menu where parent_id=0";
$result=mysql_query($sql,$Con);

//Èç¹uÒ»¼¶²Ëµ¥´aeÔÚÔo¿ªÊ¼²Ëµ¥µÄÏÔʾ
if(mysql_num_rows($result)>0) ShowTreeMenu($Con,$result,$layer,$ID);

//=============================================
//ÏÔʾÊ÷ÐͲ˵¥º¯Êý ShowTreeMenu($con,$result,$layer)
//$con£ºÊý¾Ý¿aÁ¬½Ó
//$result£ºÐeÒªÏÔʾµÄ²Ëµ¥¼Ç¼¼¯
//layer£ºÐeÒªÏÔʾµÄ²Ëµ¥µÄ¼¶Êý
//=============================================
function ShowTreeMenu($Con,$result,$layer)
{
//È¡µÃÐeÒªÏÔʾµÄ²Ëµ¥µÄÏiÄ¿Êý
$numrows=mysql_num_rows($result);

//¿ªÊ¼ÏÔʾ²Ëµ¥£¬Ã¿¸o×Ӳ˵¥¶¼ÓÃÒ»¸o±i¸ñÀ´±iʾ
echo "

";

for($rows=0;$rows<$numrows;$rows++)
{
//½«µ±Ç°²Ëµ¥ÏiÄ¿µÄÄÚÈݵ¼ÈeÊý×e
$menu=mysql_fetch_array($result);

//ÌaÈ¡²Ëµ¥ÏiÄ¿µÄ×Ӳ˵¥¼Ç¼¼¯
$sql="select * from menu where parent_id=$menu[id]";
$result_sub=mysql_query($sql,$Con);

echo "

";
//Èç¹u¸Ã²Ëµ¥ÏiÄ¿ÓÐ×Ӳ˵¥£¬ÔoÌi¼ÓJavaScript onClickÓi¾a
if(mysql_num_rows($result_sub)>0)
{
echo "";
echo "";
echo " ";

//Èç¹u¸Ã²Ëµ¥ÏiÄ¿ÓÐ×Ӳ˵¥£¬ÔoÏÔʾ×Ӳ˵¥
if(mysql_num_rows($result_sub)>0)
{
//Ö¸¶¨¸Ã×Ӳ˵¥µÄIDºÍstyle£¬ÒÔ±aºÍonClickÓi¾aÏa¶ÔÓ¦
echo "<tr id=Menu".$GLOBALS["ID"]++." style='display:none'>";
echo "

";
echo "";
}
//¼ÌÐøÏÔʾÏÂÒ»¸o²Ëµ¥ÏiÄ¿
}
echo "
";
//½«¼¶Êý¼Ó1
$layer++;
//µÝ¹eµ÷ÓÃShowTreeMenu()º¯Êý£¬Éu³É×Ӳ˵¥
ShowTreeMenu($Con,$result_sub,$layer);
//×Ӳ˵¥´¦ÀiÍe³É£¬*µ»Øµ½µÝ¹eµÄÉÏÒ»²a£¬½«¼¶Êý¼o1
$layer--;
echo "
";
}
?>

ÔÚÉÏÃaeµÄphpÒ³ÃaeÀiÃae£¬ÎÒ¶¨ÒaÁËÒ»¸oº¯ÊýShowTreeMenu()£¬Í¨¹ýÕa¸oº¯ÊýµÄµ÷Ó㬻a´ÓÊý¾Ý¿aÖеݹeµÄµ÷³oÿ¸o²Ëµ¥ÏiÄ¿£¬²¢ÏÔʾÔÚÒ³ÃaeÉÏÁË£º£(C)

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8