In case you are unaware, the book "PHP Web Development" by Laura Luke
is one of the most popular php books if not the definitive php book. In the book, they provide the following example on creating a bulletin board.
What I need help in figuring out is their claim on passing a variable:
According to them, display_tree($SESSION['expanded']); should yield different results for
$GET['expand'] ==3 and of 'all' as far as the value for $start in the display_tree function is concerned.
If $_SESSION['expand']=6, then function display_tree is supposed to set the value on $start to 6 for the program to work, but a careful study will tell you that it is not feasible.
Thanks.
Code:
<?php
include ('include_fns.php');
session_start();
// check if we have created our session variable
if(!isset($_SESSION['expanded']))
{
$_SESSION['expanded'] = array();
}
// check if an expand button was pressed
// expand might equal 'all' or a postid or not be set
if(isset($_GET['expand']))
{
if($_GET['expand'] == 'all')
expand_all($_SESSION['expanded']);
else
$_SESSION['expanded'][$_GET['expand']] = true; /// what if $_SESSION['expand']=6
}
// check if a collapse button was pressed
// collapse might equal all or a postid or not be set
if(isset($_GET['collapse']))
{
if($_GET['collapse']=='all')
$_SESSION['expanded'] = array();
else
unset($_SESSION['expanded'][$_GET['collapse']]);
}
do_html_header('Discussion Posts');
display_index_toolbar();
// display the tree view of conversations
display_tree($_SESSION['expanded']);
do_html_footer();
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>';
}
?>