Specifications
Building Practical PHP and MySQL Projects
P
ART V
730
After all that’s done, we call the root treenode’s display function (this is back in display_tree()),
as follows:
$tree->display($row, $sublist);
The display() function begins by checking whether this is the dummy root node:
if($this->m_depth>-1)
In this way, the dummy can be left out of the display. We don’t want to completely skip the
root node though. We do not want it to appear, but it needs to notify its children that they need
to display themselves.
The function then starts drawing the table containing the articles. It uses the modulus operator
(
%) to decide what color background this row should have (hence they alternate):
//color alternate rows
echo “<tr><td bgcolor = “;if ($row%2)
echo “‘#cccccc’>”;
else
echo “‘#ffffff’>”;
It then uses the $m_depth member variable to work out how much to indent the current item.
You will see by looking back at the figures that the deeper level a reply is on, the further it is
indented. This is done as follows:
// indent replies to the depth of nesting
for($i = 0; $i<$this->m_depth; $i++)
{
echo “<img src = ‘images/spacer.gif’ height = 22
width = 22 alt = ‘’ valign = bottom>”;
}
The next part of the function works out whether to supply a plus or minus button or nothing
at all:
// display + or - or a spacer
if ( !$sublist && $this->m_children && sizeof($this->m_childlist))
// we’re on the main page, have some children, and they’re expanded
{
// we are expanded - offer button to collapse
echo “<a href = ‘index.php?collapse=”.
$this->m_postid.”#$this->m_postid’
><img src = ‘images/minus.gif’ valign = bottom
height = 22 width = 22 alt = ‘Collapse Thread’ border = 0></a>”;
}
else if(!$sublist && $this->m_children)
{
35 7842 CH29 3/6/01 3:34 PM Page 730