13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

760 Chapter 31 Building <strong>Web</strong> Forums<br />

$this->m_title." - ".$this->m_poster." - ".<br />

reformat_date($this->m_posted)."";<br />

You then change the color for the next row:<br />

// increment row counter to alternate colors<br />

$row++;<br />

After that, you add some code that will be executed by all treenodes, including the root<br />

one, as follows:<br />

// call display on each of this node's children<br />

// note a node will only have children in its list if exp<strong>and</strong>ed<br />

$num_children = sizeof($this->m_childlist);<br />

for($i = 0; $im_childlist[$i]->display($row, $sublist);<br />

}<br />

return $row;<br />

Again, this is a recursive function call, which calls on each of this node’s children to display<br />

themselves.You pass them the current row color <strong>and</strong> get them to pass it back when<br />

they are finished with it so that you can keep track of the alternating color.<br />

That’s it for this class.The code is fairly complex.You might like to experiment with<br />

running the application <strong>and</strong> then come back to look at it again when you are comfortable<br />

with what it does.<br />

Viewing Individual Articles<br />

The display_tree() call gives you links to a set of articles. If you click one of these<br />

articles, you will go to the view_post.php script, with a parameter of the postid of the<br />

article to be viewed. Sample output from this script is shown in Figure 31.7.<br />

The view_post.php script, shown in Listing 31.6, shows the message body, as well as<br />

the replies to this message.The replies are again displayed as a tree but completely<br />

exp<strong>and</strong>ed this time, <strong>and</strong> without any plus or minus buttons.This is the effect of the<br />

$sublist switch coming into action.<br />

Listing 31.6<br />

view_post.php—Displays a Single Message Body<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!