tailieunhanh - PHP and MySQL Web Development - P144

PHP and MySQL Web Development - P144: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | Viewing the Tree of Articles 687 The main role of this function is to create the root node of the tree use it both to display the whole index and to create subtrees of replies on the page. As you can see it takes three first expanded is the list of article postids to display in an expanded second row is an indicator of the row number which will be used to work out the alternating colors of the rows in the list. The third parameter start tells the function where to start displaying is the postid of the root node for the tree to be created and displayed. If we are displaying the whole thing as we are on the main page this will be 0 zero meaning display all the articles with no parent. If this parameter is 0 we set sublist to false and display the whole tree. If the parameter is greater than 0 we use it as the root node of the tree to display set sublist to true and build and display only part of the tree. We will use this in the script. The most important thing this function does is instantiate an instance of the treenode class that represents the root of the is not actually an article but it acts as the parent of all the first level articles which have no parent. After the tree has been constructed we simply call its display function to actually display the list of articles. Using the treenode Class The code for the treenode class is shown in Listing . You might find it useful at this stage to look over Chapter 6 Object-Oriented PHP to remind yourself how classes work. Listing treenode Class from The Backbone of the Application php functions for loading contructing and displaying the tree are in this file class treenode each node in the tree has member variables containing all the data for a post except the body of the message var m_postid var m_title var m_poster var m_posted var m_children var m_childlist var m_depth function treenode postid .

TỪ KHÓA LIÊN QUAN