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.

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

Listing 31.8<br />

Continued<br />

$conn = db_connect();<br />

$query = "select message from body where postid = '".$postid."'";<br />

$result = $conn->query($query);<br />

if($result->num_rows>0) {<br />

$this_row = $result->fetch_array();<br />

return $this_row[0];<br />

}<br />

}<br />

These first two functions retrieve an article’s header <strong>and</strong> body, respectively, from the database.<br />

Listing 31.11 add_quoting() Function from discussion_fns.php—Indents a<br />

Message Text with > Symbols<br />

function add_quoting($string, $pattern = '> ') {<br />

// add a quoting pattern to mark text quoted in your reply<br />

return $pattern.str_replace("\n", "\n$pattern", $string);<br />

}<br />

The add_quoting() function reformats the string to begin each line of the original text<br />

with a symbol, which defaults to >.<br />

After the user types in his reply <strong>and</strong> clicks the Post button, he is taken to the<br />

store_new_post.php script. Sample output from this script is shown in Figure 31.9.<br />

Figure 31.9<br />

The new post is now visible in the tree.

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

Saved successfully!

Ooh no, something went wrong!