tailieunhanh - Phát triển web với PHP và MySQL - p 76

Building Web Forums CHAPTER 29 725 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 | Building Web Forums 725 Chapter 29 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 treenode The Backbone of the Application functions for loading contracting 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 title poster posted children expand depth expanded sublist the constructor sets up the member variables but more importantly recursively creates lower parts of the tree this- m_postid postid this- m_title title this- m_poster poster this- m_posted posted this- m_children children this- m_childlist array this- m_depth depth we only care what is below this node if it has children and is marked to be expanded sublists are always expanded if sublist expand children 29 Building Web Forums conn db_connect Building Practical PHP and MySQL Projects 726 Part V Listing Continued query select from header where parent postid order by posted result mysql_query query for count 0 row @mysql_fetch_array result count if sublist expanded row postid true expand true else expand false this- m_childlist count new treenode row postid row title row poster row posted row children expand depth 1 expanded sublist function display row sublist false as this is an object it is responsible for displaying itself row tells us what row of the display we are up to so we know what color it should be sublist tells us whether we are on the main page or the message page. Message pages should have sublist true. On

TỪ KHÓA LIÊN QUAN