Specifications
Building Web Forums
C
HAPTER 29
29
BUILDING WEB
FORUMS
731
// we are collapsed - offer button to expand
echo “<a href = ‘index.php?expand=”.
$this->m_postid.”#$this->m_postid’><img src = ‘images/plus.gif’
height = 22 width = 22 alt = ‘Expand Thread’ border = 0></a>”;
}
else
{
// we have no children, or are in a sublist, do not give button
echo “<img src = ‘images/spacer.gif’ height = 22 width = 22
alt = ‘’valign = bottom>”;
}
Next, we display the actual details of this node:
echo “ <a name = $this->m_postid ><a href =
‘view_post.php?postid=$this->m_postid’>$this->m_title -
$this->m_poster - “.reformat_date($this->m_posted).”</a>”;
echo “</td></tr>”;
We change the color for the next row:
// increment row counter to alternate colors
$row++;
After that, there is some code that will be executed by all treenodes, including the root one, as
follows:
// call display on each of this node’s children
// note a node will only have children in its list if expanded
$num_children = sizeof($this->m_childlist);
for($i = 0; $i<$num_children; $i++)
{
$row = $this->m_childlist[$i]->display($row, $sublist);
}
return $row;
Again this is a recursive function call, which calls on each of this node’s children to display
themselves. We pass them the current row color and get them to pass it back when they are fin-
ished with it, so we can keep track of the alternating color.
That’s it for this class. The code is fairly complex. You might like to experiment with running the
application and then come back to look at it again when you are comfortable with what it does.
Viewing Individual Articles
The display_tree() call ends up giving us links to a set of articles. If we click one of these
articles, we will go to the
view_post.php script, with a parameter of the postid of the article
to be viewed. Sample output from this script is shown in Figure 29.7.
35 7842 CH29 3/6/01 3:34 PM Page 731