简体   繁体   English

在树结构php sql中显示数据

[英]Displaying data in tree structure php sql

My website(php) has some categories and corresponding sub categories. 我的网站(php)有一些类别和相应的子类别。

I want to display them in tree structure. 我想以树形结构显示它们。

First of all the categories should be displayed with a plus sign , when someone clicks the plus sign , below categories should slide down and corresponding sub categories should display. 首先应该使用加号显示类别,当有人点击加号时,下面的类别应该向下滑动并显示相应的子类别。

This is very common thin i found on many web sites but unable to find how to do it. 这是我在许多网站上发现的非常常见的瘦,但无法找到如何做到这一点。

pls suggest how to implement this structure. 请建议如何实现这种结构。

Thanks. 谢谢。

where (M) (V) (C) points to MVC application structure, see: 其中(M)(V)(C)指向MVC应用程序结构,请参阅:
http://oreilly.com/php/archive/mvc-intro.html http://oreilly.com/php/archive/mvc-intro.html

You can do it using a Nested set model or an Adjecency list . 您可以使用嵌套集模型Adjecency列表来执行此操作。 Read up on those, there's a lot of example code available. 阅读这些内容,有很多可用的示例代码。 For more information, read http://en.wikipedia.org/wiki/Tree_(data_structure ) . 有关更多信息,请阅读http://en.wikipedia.org/wiki/Tree_(data_structure )。

Use jQuery, my demo js (this is a plugin wrote in 3 minutes): 使用jQuery,我的演示js(这是一个插件在3分钟内写完):

    (function($){  
 $.fn.subcath = function() {  
   return this.each(function() {  
   obj = $(this);     
   var subcath=$('.subcath', obj);
   alert(obj.html());
   obj.click(function (){
        subcath.toggle('slow');
    });
   });
    }})(jQuery);  

HTML: HTML:

     <SCRIPT language="JavaScript" SRC="jquery.js"></SCRIPT> 
     <SCRIPT language="JavaScript" SRC="my_plugin.js"></SCRIPT> 
   <script>
         $().ready(function() {  
            $('.subcath').hide();
                $('.menu').subcath();
          });
    </script>  

    <ul class='menu'> 
     <div class="cathegory" >
            <li class="cath" >Cath1</li>
        <div class="sub_cathegory" >
            <ul class="subcath"> 
                 <li class="sub_el" >Cath1</li>
                 <li class="sub_el" >Cath2</li>
            </ul> 
        </div>
     </div>
         <div class="cathegory" >
            <li class="cath" >Cath1</li>
        <div class="sub_cathegory" >
            <ul class="subcath"> 
                      <li class="subcath_el" >Cath3</li>
                  <li class="subcath_el" >Cath4</li>
            </ul>
        </div>
     </div>
    </ul>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM