php+mysql+js实现树形菜单代码
栏目:php教程时间:2014-05-17 13:32:07
-
- */
- ?>
- <html>
- <head>
- <meta http-equiv="content-type" content="text/html; charset=gb2312" />
- <title>类别目录树</title>
- <script type="text/网页特效">
- function showmenu(menuid)
- {
- if(menuid.style.display=="none"){
- menuid.style.display="";
- }
- else{
- menuid.style.display="none";
- }
- }
- </script>
- <style>
- body{margin:0px;}
- table tr td{font-size:12px}
- </style>
- </head>
- <body>
- <?php
- $globals["id"] =1;
- $layer=1;
-
- $con=mysql_connect("localhost","root","123456");
- mysql_select_db("demo");
-
- $sql="select * from think_news where `f_id`=0";
- $result=mysql_query($sql,$con);
-
- if(mysql_num_rows($result)>0) showtreemenu($con,$result,$id);
- function showtreemenu($con,$result,$layer)
- {
-
- $numrows=mysql_num_rows($result);
-
- echo "<table cellpadding='0' cellspacing='0' border='0' width='100%'>";
- for($rows=0;$rows<$numrows;$rows++)
- {
-
- $menu=mysql_fetch_array($result);
-
- $sql="select * from think_news where f_id=$menu[id]";
- $result_sub=mysql_query($sql,$con);
- echo "<tr>";
-
- if(mysql_num_rows($result_sub)>0)
- {
- echo "<td width='20' valign= 'top' ><span onclick='showmenu(menu".$globals['id'].")' ><img src='menu_minus.gif' border='0' align='absmiddle'></span></td>";
- echo "<td class='menu' >";
- }
- else
- {
- echo "<td width='20'><img src='menu_plus.gif' border='0' align='absmiddle' > </td>";
- echo "<td class='menu'>";
- }
-
- echo $menu["title"];
- echo "</td></tr>";
-
- if(mysql_num_rows($result_sub)>0)
- {
-
- echo "<tr id=menu".$globals["id"]++." style='display:none'>";
- echo "<td width='20'> </td>";
- echo "<td>";
-
- $layer++;
-
- showtreemenu($con,$result_sub,$layer);
-
- echo "</td></tr>";
- }
-
- $layer--;
- }
- echo "</table>";
- }
------分隔线----------------------------
------分隔线----------------------------