Specifications

unset($expanded);
else
unset($expanded[$collapse]);
}
do_html_header(“Discussion Posts”);
display_index_toolbar();
// display the tree view of conversations
display_tree($expanded);
do_html_footer();
?>
This script uses three variables to do its job. They are
The session variable $expanded, which keeps track of which threads are expanded. This
can be maintained from view to view, so we can have multiple threads expanded. This
variable is an associative array that contains the postid of articles which will have their
replies displayed expanded.
The parameter $expand, which tells the script which new threads to expand.
The parameter $collapse, which tells the script which threads to collapse.
When we click a plus or minus symbol or the Expand or Collapse button, they will re-call the
index.php script with new parameters for $expand or $collapse. We use $expanded from
page to page to track which threads should be expanded in any given view.
The script begins by starting a session and adding the $expanded variable as a session variable
if this has not already been done.
After that, the script checks whether it has been passed an $expand or $collapse parameter
and modifies the $expanded array accordingly. Look at the code for the $expand parameter:
if($expand)
{
if($expand == ‘all’)
expand_all($expanded);
else
$expanded[$expand] = true;
}
If we have clicked on the Expand button, the function expand_all() is called to add all the
threads that have replies into the $expanded array. (Well look at this in a moment.)
Building Practical PHP and MySQL Projects
P
ART V
722
LISTING 29.2 Continued
35 7842 CH29 3/6/01 3:34 PM Page 722