Đang chuẩn bị liên kết để tải về tài liệu:
PHP and MySQL Web Development - P144

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

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 structure.We use it both to display the whole index and to create subtrees of replies on the view_post.php page. As you can see it takes three parameters.The first expanded is the list of article postids to display in an expanded fashion.The 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 articles.This 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 view_post.php script. The most important thing this function does is instantiate an instance of the treenode class that represents the root of the tree.This 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 29.5. You might find it useful at this stage to look over Chapter 6 Object-Oriented PHP to remind yourself how classes work. Listing 29.5 treenode Class from treenode_class.php 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 .