仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1080|回复: 19
打印 上一主题 下一主题

[学习教程] PHP网页编程之实际上完成真正意义的无穷级别菜单

[复制链接]
活着的死人 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-4 00:22:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
PHP于1994年由Rasmus Lerdorf创建,刚刚开始是Rasmus Lerdorf为了要维护个人网页而制作的一个简单的用Perl语言编写的程序。菜单   好久没用php了,为了加深数据布局的根基常识(为测验筹办),实习一下根基的算法,固然仍是为了今后利用php做菜单的时分以免费事。
算法:数据布局中的最根基的树与二叉树的转换
人人对付着看吧!由于只是为了熟习一下算法,没有做详细的测试,同时对数据库的操作没有封装成类,人人假如需求可以自行修正或和我接洽!


Your data must save like this:
id,topic,child_l,parent,child_r,content

file name:
show.inc.php
codes:
==================================================
<?

class shows{
    var $items;
    var $the_stack;
    var $count=0;
   

    function find($l_value) {
        for($j=1;$j<=$this->items["info_all"];$j++) {
            if($l_value==$this->items["d_id][$j]"])
            { return($j);exit; }
        
        }
            
    }
        
        
    function m_l_r_list($i) {
   
        if(($this->items["f_node][$i]"]==0)&&($this->items["r_node][$i]"]==0)&&($this->items["l_node][$i]"]!=-1))
        {//if it is root node!!!
            echo "<table><tr><td>";
            echo "<img id=image".$i." src=http://www.163design.net/"c.gif\" onclick=outliner() style=\"cursor:hand\" child=\"".$i."ALL\" NAME=\"NAME_".$i."ALL\">";
            echo "<a href=\"".$this->pages_0($this->items["d_id][$i]"])."?d_id=".$this->items["d_id][$i]"]."\" target=\"rightFrame\">".$this->items["node_value][$i]"]."</a>";
            echo " <a href=addnode.php?id=".$this->items["d_id][$i]"]." target=\"rightFrame\"><font size=2 color=red>Add</font></a>";
            echo "</td></tr></table>";
            echo "<div class=collapsed id=".$i."ALL>";
            $i=$this->find($this->items["l_node][$i]"]);
            $this->count=$this->count+2;
            $this->m_l_r_list($i);
            exit;
        }
        if(($this->items["f_node][$i]"]==0)&&($this->items["r_node][$i]"]==0)&&($this->items["l_node][$i]"]==-1))
        {
            exit;
        }
         if(($this->items["f_node][$i]"]!=0)&&($this->items["r_node][$i]"]!=0)&&($this->items["l_node][$i]"]!=0))
         {//if node have left and right child
             $current_node=$this->items["d_id][$i]"];
            
             if(($this->items["l_node][$i]"]==-1)&&($this->items["r_node][$i]"]==-1)) {
                $i=$this->find($this->items["f_node][$i]"]);
                if(($this->items["r_node][$i]"]==$current_node)) {//his parent use right point
                    $this->items["r_node][$i]"]=-1;
                }
                if(($this->items["l_node][$i]"]==$current_node)) {//his parent use left point
                    $this->items["l_node][$i]"]=-1;
                }
                $this->count=$this->count-2;
                $this->m_l_r_list($i);
            }//if left child and right child have been visited up to his parent node
            
             if(($this->items["l_node][$i]"]!=-1)&&($this->items["r_node][$i]"]!=-1)) {
                echo "<table><tr><td>";
                for ($k=0;$k<$this->count;$k++) { echo " ";}
                echo "<img id=image".$i." src=http://www.163design.net/"c.gif\" onclick=outliner() style=\"cursor:hand\" child=\"".$i."ALL\" NAME=\"NAME_".$i."ALL\">";
                echo "<a href=\"main.php?d_id=".$this->items["d_id][$i]"]."\" target=\"rightFrame\">".$this->items["node_value][$i]"]."</a>";
                //echo $this->items["node_value][$i]"];
                echo " <a href=addnode.php?id=".$this->items["d_id][$i]"]." target=\"rightFrame\"><font size=2 color=red>Add</font></a>";
                echo " <a href=delnode.php?id=".$this->items["d_id][$i]"]."><font size=2 color=red>Del</font></a>";
                echo "</td></tr></table>";
                echo "<div class=collapsed id=".$i."ALL>";
                $i=$this->find($this->items["l_node][$i]"]);//visite left child node
                 $this->count=$this->count+2;
                 $this->m_l_r_list($i);
            }//if left child node and right child node have not been visited
            
             if(($this->items["l_node][$i]"]==-1)&&($this->items["r_node][$i]"]!=-1)) {
                 $i=$this->find($this->items["r_node][$i]"]);//visite right child node
                 $this->m_l_r_list($i);
            }//if left child node have been visited and right child node have not been visited     
            
         }
         
        if(($this->items["f_node][$i]"]!=0)&&($this->items["r_node][$i]"]==0)&&($this->items["l_node][$i]"]!=0))
        {//if node only have left child
            $current_node=$this->items["d_id][$i]"];
            if($this->items["l_node][$i]"]!=-1) {
                echo "<table><tr><td>";
                for ($k=0;$k<$this->count;$k++) { echo " ";}
                echo "<img id=image".$i." src=http://www.163design.net/"c.gif\" onclick=outliner() style=\"cursor:hand\" child=\"".$i."ALL\" NAME=\"NAME_".$i."ALL\">";
                echo "<a href=\"main.php?d_id=".$this->items["d_id][$i]"]."\" target=\"rightFrame\">".$this->items["node_value][$i]"]."</a>";
                //echo $this->items["node_value][$i]"];
                echo " <a href=addnode.php?id=".$this->items["d_id][$i]"]." target=\"rightFrame\"><font size=2 color=red>Add</font></a>";
                echo " <a href=delnode.php?id=".$this->items["d_id][$i]"]."><font size=2 color=red>Del</font></a>";
                echo "</td></tr></table>";
                echo "<div class=collapsed id=".$i."ALL>";
                $i=$this->find($this->items["l_node][$i]"]);//visite left child node
                $this->count=$this->count+2;
                $this->m_l_r_list($i);
                exit;
            }//if his left child node have not been visited
            
            if($this->items["l_node][$i]"]==-1) {
                echo "</div>";
                $i=$this->find($this->items["f_node][$i]"]);
                if(($this->items["r_node][$i]"]==$current_node)) {//his parent use right point
                    $this->items["r_node][$i]"]=-1;
                }
                if(($this->items["l_node][$i]"]==$current_node)) {//his parent use left point
                    $this->items["l_node][$i]"]=-1;
                    $this->count=$this->count-2;
                }
                $this->m_l_r_list($i);
                exit;
            }//if his left child node have been visite,up to his parent node

            
        }
        if(($this->items["f_node][$i]"]!=0)&&($this->items["r_node][$i]"]!=0)&&($this->items["l_node][$i]"]==0))
        {//if node only have right child
            $current_node=$this->items["d_id][$i]"];
            $j=$this->find($this->items["f_node][$i]"]);
            if($this->items["r_node][$i]"]!=-1) {
                echo "<table><tr><td>";
                for ($k=0;$k<$this->count;$k++) { echo " ";}
                echo "<a href=\"main.php?d_id=".$this->items["d_id][$i]"]."\" target=\"rightFrame\">".$this->items["node_value][$i]"]."</a>";
                //echo $this->items["node_value][$i]"];
                echo " <a href=addnode.php?id=".$this->items["d_id][$i]"]." target=\"rightFrame\"><font size=2 color=red>Add</font></a>";
                echo " <a href=delnode.php?id=".$this->items["d_id][$i]"]."><font size=2 color=red>Del</font></a>";
                echo "</td></tr></table>";
                $i=$this->find($this->items["r_node][$i]"]);//visite right child node
                $this->m_l_r_list($i);
                exit;
            }//if his right child node have not been visited
            
            if($this->items["r_node][$i]"]==-1) {
                $i=$this->find($this->items["f_node][$i]"]);
                if(($this->items["r_node][$i]"]==$current_node)) {//his parent use right point
                    $this->items["r_node][$i]"]=-1;
                }
                if(($this->items["l_node][$i]"]==$current_node)) {//his parent use left point
                    $this->items["l_node][$i]"]=-1;
                    $this->count=$this->count-2;
                }
                $this->m_l_r_list($i);
                exit;
            }//if his right child node have been visite,up to his parent node
            
            
        }
        if(($this->items["f_node][$i]"]!=0)&&($this->items["l_node][$i]"]==0)&&($this->items["r_node][$i]"]==0))
        {//if this node haven't child node,print it and up to his parent
         //node his parent left or right child have been visited
            $current_node=$this->items["d_id][$i]"];
            $j=$i;
            $i=$this->find($this->items["f_node][$i]"]);//up to parent
            //echo $this->items["l_node][$i]"];
            if(($this->items["r_node][$i]"]==$current_node)) {//his parent use right point
                echo "<table><tr><td>";
                for ($k=0;$k<$this->count;$k++) { echo " ";}
                echo "<a href=\"main.php?d_id=".$this->items["d_id][$j]"]."\" target=\"rightFrame\">".$this->items["node_value][$j]"]."</a>";
                //echo $this->items["node_value][$j]"];
                echo " <a href=addnode.php?id=".$this->items["d_id][$j]"]." target=\"rightFrame\"><font size=2 color=red>Add</font></a>";
                echo " <a href=delnode.php?id=".$this->items["d_id][$j]"]."><font size=2 color=red>Del</font></a>";
                echo "</td></tr></table>";
                echo "</div>";
                $this->items["r_node][$i]"]=-1;
                    
            }
            if(($this->items["l_node][$i]"]==$current_node)) {//his parent use left point
               
                echo "<table><tr><td>";
                for ($k=0;$k<$this->count;$k++) { echo " ";}
                echo "<a href=\"main.php?d_id=".$this->items["d_id][$j]"]."\" target=\"rightFrame\">".$this->items["node_value][$j]"]."</a>";
                //echo $this->items["node_value][$j]"];
                echo " <a href=addnode.php?id=".$this->items["d_id][$j]"]." target=\"rightFrame\"><font size=2 color=red>Add</font></a>";
                echo " <a href=delnode.php?id=".$this->items["d_id][$j]"]."><font size=2 color=red>Del</font></a>";
                echo "</td></tr></table>";
                echo "</div>";
                $this->items["l_node][$i]"]=-1;
                $this->count=$this->count-2;
               
            }
            $this->m_l_r_list($i);
            exit;
        }
   
    }
   
    function pages_0($d_id){//
        include("conn_db.php");
        $Sql_Query="select * from node_page where d_id=$d_id";
        $Query_Db=mysql_query($Sql_Query,$Connect);
        $MyPage=mysql_fetch_array($Query_Db);            
        include("conn_close.php");
        if($MyPage["d_page"]!='')
            {
                return $MyPage["d_page"];
            }   
        else return "init.php";
        }
    function pages($d_id){//
        include("conn_db.php");
        $Sql_Query="select * from node_page where d_id=$d_id";
        $Query_Db=mysql_query($Sql_Query,$Connect);
        $MyPage=mysql_fetch_array($Query_Db);            
        include("conn_close.php");
        return $MyPage["d_page"];
        }   
        
    function showinfo_0($status){//
        include("conn_db.php");
        $Sql_Query="select * from department order by d_id";
        $Query_Db=mysql_query($Sql_Query,$Connect);
        $info_all=mysql_num_rows($Query_Db);
        $this->items["info_all"]=$info_all;
        if($status==1) {//when status=1 show all data gets from database
            $MNums=$info_all;
            }
        if($status==0) {//when status=0 show 6 messages gets from database
            $MNums=6;
            }
        for($i=1;$i<=$MNums;$i++)
            {
            $Messages=mysql_fetch_array($Query_Db);
            $this->items["d_id][$i]"]=$Messages["d_id"];
            $this->items["f_node][$i]"]=$Messages["f_node"];
            $this->items["node_value][$i]"]=$Messages["node_value"];
            $this->items["l_node][$i]"]=$Messages["l_node"];
            $this->items["r_node][$i]"]=$Messages["r_node"];
            }
        include("conn_close.php");
        }   
}  不懂的问题有很多高手帮你解决。但不要认为你是新手,就不能帮助别人,比如今天你学会了怎样安装PHP,明天还可能有朋友会问这个问题,你就可以给他解答,不要认为这是浪费时间,忙别人其实就是帮助自己。
老尸 该用户已被删除
沙发
发表于 2015-2-4 12:49:38 | 只看该作者
兴趣是最好的老师,百度是最好的词典。
小妖女 该用户已被删除
板凳
发表于 2015-2-7 07:00:48 | 只看该作者
环境搭建好,当你看见你的浏览器输出“it works\\\\\\\"时你一定是喜悦的。在你解决问题的时候,我强烈建议多读php手册。
透明 该用户已被删除
地板
发表于 2015-2-20 23:39:25 | 只看该作者
写的比较杂,因为我也是个新手,不当至于大家多多指正。
因胸联盟 该用户已被删除
5#
发表于 2015-2-25 22:02:54 | 只看该作者
对于初学者来说不推荐去拿钱买的。当然如果一个网站你经常去用,而且里面的资料也比较有用,最好还是买个会员比较好,毕竟那些也是别人的工作成果。
若相依 该用户已被删除
6#
发表于 2015-2-28 14:16:40 | 只看该作者
使用zendstdio 写代码的的时候,把tab 的缩进设置成4个空格是很有必要的
小女巫 该用户已被删除
7#
发表于 2015-3-1 17:29:56 | 只看该作者
首先我是坚决反对新手上来就用框架的,因为对底层的东西一点都不了解,造成知识上的真空,会对以后的发展不利。我的观点上手了解下框架就好,代码还是手写。当然啦如果是位别的编程语言的高手的话,这个就另当别论啦。
海妖 该用户已被删除
8#
发表于 2015-3-8 12:05:20 | 只看该作者
真正的方向了,如果将来要去开发团队,你一定要学好smarty ,phplib这样的模板引擎,
爱飞 该用户已被删除
9#
发表于 2015-3-15 22:27:43 | 只看该作者
如果你可以写完像留言板这样的程序,那么你可以去一些别人的代码了,
飘灵儿 该用户已被删除
10#
发表于 2015-3-22 17:10:51 | 只看该作者
说点我烦的低级错误吧,曾经有次插入mysql的时间 弄了300年结果老报错,其实mysql的时间是有限制的,大概是到203X年  具体的记不清啦,囧。
冷月葬花魂 该用户已被删除
11#
发表于 2015-4-2 22:13:36 | 只看该作者
其实也不算什么什么心得,在各位大侠算是小巫见大巫了吧,望大家不要见笑,若其中有错误的地方请各位大虾斧正。
精灵巫婆 该用户已被删除
12#
发表于 2015-4-6 18:20:04 | 只看该作者
装在C盘下面可以利用windows的ghost功能可以还原回来(顺便当做是重转啦),当然啦我的编译目录要放在别的盘下,不然自己的劳动成果就悲剧啦。
不帅 该用户已被删除
13#
发表于 2015-4-12 20:53:49 | 只看该作者
实践是检验自己会不会的真理。
灵魂腐蚀 该用户已被删除
14#
发表于 2015-4-18 01:20:38 | 只看该作者
php里的数组为空的时候是不能拿来遍历的;(这个有点低级啊,不过我刚被这个边界问题墨迹了好长一会)
山那边是海 该用户已被删除
15#
发表于 2015-4-20 01:56:20 | 只看该作者
其实也不算什么什么心得,在各位大侠算是小巫见大巫了吧,望大家不要见笑,若其中有错误的地方请各位大虾斧正。
若天明 该用户已被删除
16#
发表于 2015-4-21 04:34:01 | 只看该作者
装在C盘下面可以利用windows的ghost功能可以还原回来(顺便当做是重转啦),当然啦我的编译目录要放在别的盘下,不然自己的劳动成果就悲剧啦。
再现理想 该用户已被删除
17#
发表于 2015-5-4 20:30:26 | 只看该作者
写js我最烦的就是 ie 和 firefox下同样的代码 结果显示的结果千差万别,还是就是最好不要用遨游去调试,因为有时候遨游是禁用js的,有可能代码是争取结果被遨游折腾的认为是代码写错。
活着的死人 该用户已被删除
18#
 楼主| 发表于 2015-5-6 00:11:21 | 只看该作者
建议加几个专业的phper的群,当然啦需要说话的人多,一处一点问题能有人回答你的,当然啦要让人回答你的问题,平时就得躲在里面聊天,大家混熟啦,愿意回答你问题的人自然就多啦。
只想知道 该用户已被删除
19#
发表于 2015-6-10 00:14:59 | 只看该作者
使用zendstdio 写代码的的时候,把tab 的缩进设置成4个空格是很有必要的
第二个灵魂 该用户已被删除
20#
发表于 2015-6-17 12:47:46 | 只看该作者
微软最近出的新字体“微软雅黑”,虽然是挺漂亮的,不过firefox  支持的不是很好,所以能少用还是少用的好。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-9-20 23:23

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表