A PHP class tree (support for infinite classification)

Source: Internet
Author: User
Tags define array php class query
Recently asked infinite classification of tree-like problems more, so a happy to write a, I just finished, we use to see, see how to achieve faster, simpler, put your tree also posted out (to query only once database) <br>
  
This is a categorized list of class trees that support infinite classification <br>
A category can have both "categories that contain subclasses" and "final Classification";<br>
  


The only advantage is * * * * * * * * only need to do a database * * * Query .<br>
  
Not very good-looking, but you can customize the changes, you can define your own CSS plus inside <br>
  
The cache has not been done, you can make up your own
  
The directory structure of the following example is this.
¦--catagory.php <br>
¦--images----tree.jsp <br>
¦--images----Treeopen.gif <br>
¦--images----Treeclose.gif <br>
¦--images----Line.gif <br>
  
/****************tree.jsp********************/
function expand (ID) {
node = document.all (' node ' +id);
if (node.style.display== ') {
Node.style.display = ' None ';
Document.images (' img ' +id). src = imgopen;
}else{
Node.style.display = ';
Document.images (' img ' +id). src = imgclose;
}
}
  
/****************catagory.php********************/
<?php
  
Define (' Catagory_tree_expend_none ', 0);
Define (' Catagory_tree_expend_all ', 1);
  
Class catagory{
Basic classification data
var $treeData = array ();
The hierarchical array of classifications, with the ID value of the category as the keyword for the array
var $treePList = array ();
The relationship of self-classification corresponding to superior class
var $treeCList = array ();
/*
* This is a template for large categories
*
* Number of __id__ categories
* Name of the __name__ category
* __image__ Category The image name shown earlier $imgOpen or $imgClose
* Whether the __OPEN__ classification is currently expanded
* __inner__ the position displayed by the sub category




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.