Site Administration Page 6 - Talk To Me! |
The script "list.php" is designed to display a threaded list of all the comments posted for a specific article - it accomplishes this via the buildTree() function.
The buildTree() function is the guts of this application. It is a recursive function that performs one query after another to create a threaded list of posts, starting from a specific branch of the tree and working its way progressively through all sub-branches. Take a look.
Let's dissect this a little. First, this function assumes that a connection to the database has been created - if you take a look, you'll see that that is one of the first things "list.php" does. It also needs some variables - the name of the database and table to perform queries on, the level at which to start building the tree structure, and the article/section identifier (passed to it as parameters). With all that information in place, buildTree() performs a SELECT query and obtains a list of "level 0" posts; it then prints these in a list. For each record thus returned, buildTree() then calls itself recursively with that record number, connects to the database again, and displays a list of all "level 1" posts. This process continues until the end of the tree is reached. The HTML list construct is used to ensure that different levels are indented appropriately. If no comments are found at level 0, a message indicating this is displayed. As you might imagine, this process can certainly test the strength of a database server, especially if there are a large number of levels. That's why you should ensure that your system has enough processing power to handle this kind of multi-level query. Each item in the list finally displayed is linked to the "details.php" page, which displays the complete content of the comment. Here's what it looks like: This article copyright Melonfire 2001. All rights reserved.
blog comments powered by Disqus |