
Displaying the Articles
Let’s look at the display_tree() function, shown in Listing 29.4.
LISTING 29.4 display_tree() Function from output_fns.php—Creates the Root Node of
the Tree Structure
function display_tree($expanded, $row = 0, $start = 0)
{
// display the tree view of conversations
global $table_width;
echo “<table width = $table_width>”;
// see if we are displaying the whole list or a sublist
if($start>0)
$sublist = true;
else
$sublist = false;
// construct tree structure to represent conversation summary
$tree = new treenode($start, ‘’, ‘’, ‘’, 1, true, -1, $expanded, $sublist);
// tell tree to display itself
$tree->display($row, $sublist);
echo “</table>”;
}
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
Building Practical PHP and MySQL Projects
P
ART V
724
35 7842 CH29 3/6/01 3:34 PM Page 724
Comentarios a estos manuales