Viewing the Tree of Articles
This script uses the following three variables to do its job:
The session variable
,which keeps track of which threads are expanded.
This variable can be maintained from view to view,so you can have multiple
variable is an associative array that contains the
of articles that will have their replies expanded.
,which tells the script which new threads to expand.
,which tells the script which threads to collapse.
When you click a plus or minus symbol or the Expand or Collapse button,this action
script with new parameters for
from page to page to track which threads should be expanded in any given view.
script begins by starting a session and adding the
as a session variable if this has not already been done.After that,the script checks
whether it has been passed an
parameter and modifies the
array accordingly. Look at the code for the
if($_GET[‘expand’] == ‘all’)
$_SESSION[‘expanded’][$_GET[‘expand’]] = true;
If you click on the Expand button,the function
is called to add all the
threads that have replies into the
array.(We look at this in a moment.)
If you try to expand a particular thread,you will be passed a
therefore add a new entry to the
array to reflect this.
function is shown in Listing 31.3.
Listing 31.3 expand_all() Function from discussion_fns.php—Processes the
$expanded Array to Expand All the Threads in the Forum
// mark all threads with children as to be shown expanded
$conn = db_connect();
$query = ‘select postid from header where children = 1’;
$result = $conn->query($query);
$num = $result->num_rows;
for($i = 0; $i<$num; $i++)
$this_row = $result->fetch_row();