You've seen how many Web sites (including this one) allow you topost comments and opinions on the material they publish. If you've everwished you had this capability on your Web site, or are simply curious asto how this is accomplished, read on.
With the table designed as per requirements, it's time to actually start writing some code. The first thing to do is to add links to the main article display page, allowing users to read and post comments.
Let's take a look at a stripped-down version of this page, called "start.php".
<?
// important information to identify this article
$section = 3;
$article = 99;
?>
<html>
<head>
</head>
<body>
<!-- snip! -->
<font face="Verdana, Arial" size="4" color="#66CC00">
<!-- getArticleTitle($section,$article) -->
Mole In A Hole
</font>
<p>
<font face="Verdana, Arial" size="2" color="Black">
<!-- getArticleAbstract($section,$article) -->
Some things just don't change - at thirty, Adrian Mole is still the
whining, unfulfilled loser we first encountered at age 13. He's still
writing to the BBC, he's still madly in love with Pandora, now a
high-profile politician in Blair's New Britannia, his family is still as
dysfunctional as ever. More in our exclusive review of the new Sue Townsend
novel.
</font>
<!-- snip! -->
</body>
</html>
Under normal circumstances, this page would receive the section and
article numbers via the URL GET method, and then display the appropriate content. For example, the article entitled "Where Are We Going?" in the politics section (7) could be obtained at the URL
start.php?section=7&article=32
while a feature on Moscow in December could be obtained from the
travel section (11) at
start.php?section=11&article=7
For explanatory purposes, I'll assume that the article number is 99
and the section number is 3 (entertainment, for those of you who care), and so I've hard-coded these values at the top of the page. I've also replaced a couple of function calls with their return values, again to make it easier to see what's going on.
Now, let's add those links.
<?
// start.php
// important information to identify this article
$section = 3;
$article = 99;
?>
<html>
<head>
</head>
<body>
<!-- snip! -->
<font face="Verdana, Arial" size="4" color="#66CC00">
<!-- getArticleTitle($section,$article) -->
Mole In A Hole
</font>
<p>
<font face="Verdana, Arial" size="2" color="Black">
<!-- getArticleAbstract($section,$article) -->
Some things just don't change - at thirty, Adrian Mole is still the
whining, unfulfilled loser we first encountered at age 13. He's still
writing to the BBC, he's still madly in love with Pandora, now a
high-profile politician in Blair's New Britannia, his family is still as
dysfunctional as ever. More in our exclusive review of the new Sue Townsend
novel.
<p>
<!-- snip! -->
<a href="post.php?section=<? echo $section; ?>&article=<? echo $article;
?>">Comment</a> on this article, or
<a href="list.php?section=<? echo $section; ?>&article=<? echo $article;
?>">view other people's comments</a>
</font>
</body>
</html>
As you can see, both "post.php" and "list.php" will now receive the
section and article numbers via the URL GET method.
Here's what the page looks like:
Shameless plug - you can find a copy of the book review above at http://www.melonfire.com/, together with lots of other cool stuff. Knock yourself out!
This article copyright Melonfire 2001. All rights reserved.