Recently, I have already asked the unlimited classification tree problem, so I am happy to write one, I just finished, everyone used it, see how to achieve faster, simpler, put your tree is also posted (to Just query one database)
This is a class tree for a classification list, supports unlimited classification
One classification can be "classified" and "final classification" and "final classification";
The only advantage ***** is only required once ***** database queries.
looks not very nice, but you can customize to modify, add css cache can define their own terms of which have not made
, you can own This is the case that the directory structure of the following example is.
| - Catagory.php
| - Images ---- Tree.jsp
| - images ---- Treeopen.gif
| - images ---- Treeclose.gif | - images ---- line.gif
/ ************************************ ***** / function expand (id) {node = document.all ('Node' ID); if (node.style.display == ') {node.style.display =' none '; document. Image ('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 {// Foundation Classification Data Var $ TREEDATA = Array (); // Classified Level Structure Arrse, as a classified ID value as an array keypar $ treeplist = array (); // Sub-class corresponding to the upper class relationship var $ TreeClist = array (); / * * This is a large classification template * * __ID__ classification number * __name__ classification name * __Image__ Category Front display Image Name $ imgopen or $ IMGCLOSE * __Open__ Category The current * __inner__ sub-classification display location * style can be arbitrarily modified according to your own needs, but cannot delete existing elements * / var $ blocktpl = '
__name__ td> TR> td> | __ inner __ td> tr> table> '; / * * This is a small classification template * * * * SEE $ blocktpl * / var $ elementtpl = ' __ name __ font> __ name __ font> A> '; var $ js = "images / tree.js"; var $ IMGOPEN =' Images / TreeOpen.gif '; var $ IMGCLOSE =' Images / Treeclose.gif '; var $ IMGLINE =' Images / line.gif '; Var $ cachfile =' ';
Var $ expestr = array (); var $ treestr = ''; var $ currentstr = ''; / * * Used to initialize, incoming classification data * * param $ data array () * / function Catagory (& $ data) {$ this -> _ init ($ data);} function _init ($ tmpdata) {$ plevel = $ clevel = $ treedata = array (); foreach ($ TMPDATA AS $ VALUE) {$ TREEDATA [ $ Value ['ID'] = $ Value; $ PLEVEL [$ Value ['PID']] [$ Value ['id'] = 'end'; $ clevel [$ value ['id'] = $ Value ['PID'];} $ this-> Treedata = & $ TREEDATA; $ this-> TreePlist = & $ pvel; $ this-> treeclist = & $ clevel;} / * * Resolution Category * * PARAM $ CATAID INT To parse the primary classification number * / function parseode ($ cataid = 0) {$ this-> result = $ this-> treeplist [$ cataid]; if ($ this-> result == null) Die ("catagory id error"); $ this-> treestr = $ this -> _ Donode ($ this-> result); $ This-> treestr. = $ this -> _ jsparse ();} function & _donode (& $ results) {$ nstr = $ estr = '; foreach ($ results $ key => $ value) {ix ($ f) This-> TreePlist [$ key])) {$ result [$ key] =
$ THIS-> Treeplist [$ key]; $ inner = $ this -> _ Donode ($ RESULT [$ Key]); $ nstr. = $ this -> _ parseNodetpl ($ key, $ inner);} else {$ estr. = $ THIS -> _ parseElementTPL ($ key);}}}}} Return $ nstr. $ Estr;} Function & _Parsenodetpl ($ cataid, $ inner) {$ data = $ this-> Treedata [$ cataid]; $ str = preg_replace |__ID__ | ', $ DATA [' ID '], $ this-> blocktpl); $ str = preg_replace (' |__name__ | ', $ data [' name '], $ STR); $ str = preg_replace (' | __IMAGE__ | ($ this-> expand? $ this-> imgclose: $ this-> imgopen), $ STR); $ str = preg_replace ('|__open___ |', ($ this-> expand? '': ' None '), $ STR); $ str = preg_replace (' |__inner__ | ', $ inner, $ str); return $ str;} function _ PARSEELEMENTTPL ($ cataid) {$ data = $ this-> Treedata [$ cataid]; $ str = preg_replace ('|__id___ |', $ data ['id'], $ this-> elementtpl); $ str = preg_replace '|__name__ |', $ data ['Name'], $ STR); $ Str = preg_replace ('|__image__ |', $ this-> imgline, $ str); return $ str;} function _jspival () {$ Str = " | |