The end result is that the article gets (Free php web host)
The end result is that the article gets displayed on the page just as intended when it was entered and is trimmed if specified. The last function in outputFunctions() is showComments(). You pass the article ID and a Boolean value that determines whether or not to show a link to allow users to add their own comments: function showComments($article, $showLink=TRUE) { Declare $conn to be global, so you can access it within the function: global $conn;. You will need to know later whether or not this article has been published. So, you grab the value of the field is_published from the article for use later: $sql = SELECT is_published . FROM cms_articles . WHERE article_id= . $article; $result = mysql_query($sql, $conn) or die( Could not look up comments; . mysql_error()); $row = mysql_fetch_array($result); $is_published = $row[ is_published ]; Next, you grab all of the comments associated with this article, including the user s name and e-mail address for each comment: $sql = SELECT co.*, usr.name, usr.email . FROM cms_comments co . LEFT OUTER JOIN cms_users usr . ON co.comment_user = usr.user_id . WHERE co.article_id= . $article . ORDER BY co.comment_date DESC ; $result = mysql_query($sql, $conn) or die( Could not look up comments; . mysql_error()); As with the outputStory() function, you just want to output out HTML whenever the outputComments function is called. If you passed TRUE as the second parameter to this function, then you put a header on the page that says Comments, along with a link for the user to add his or her own comment (if this is a registered user and the article is published). If there are no comments, this is all the user will see, and he or she will still be able to add a new comment. if ($showLink) { echo
. mysql_num_rows($result) . Comments ; if (isset($_SESSION[ user_id ]) and $is_published) { echo / Add one ; } echo
n ; } If there are comments, loop through each comment and display the comments below the article, with the newest comments first. 428 Chapter 13
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.