Page 1 of 1

Comment System

Posted: Fri Jan 03, 2003 2:18 pm
by thoughtriot
Okay, I have this news system I setup using a MySQL database, with a table called news. In news, there's ID, which is auto_increment, Title for the title of the news entry, Name for the name of the blogger, Email for the blogger's email address, Date and Time for the date and time of the entry, and Entry for the entry.

I would like to know how I could make a commenting system so below each entry, there will be a link that says X Comment(s), where X is the number of comments for that entry. And I want that link to go to a page where you can leave comments for just that entry. I think maybe having a field in the comments table called newsid or something would be what I need to identify which news post the comments go to, that way when you click the X Comments link at the bottom of an entry, it only shows that entry's comments. So, maybe someone can show me a tutorial somewhere or post what the code should look like. And here's the code for my news page in case it's needed to analyze:

Code: Select all

<p align="center" class="header1">News</p>
<form method="post" action="?z=news.php">
<select name="month" class=inputbox>
<option value="01.">January</option>
<option value="02.">February</option>
<option value="03.">March</option>
<option value="04.">April</option>
<option value="05.">May</option>
<option value="06.">June</option>
<option value="07.">July</option>
<option value="08.">August</option>
<option value="09.">September</option>
<option value="10.">October</option>
<option value="11.">November</option>
<option value="12.">December</option>
</select>
<select name="year" class=inputbox>
<option value=".03">2003</option>
<option value=".02">2002</option>
</select>
<input type="submit" class=button value="Go">
</form>
<?
include("news/connect.php");
if ($month == '') {
?>
<?
$curmonth = "" . date("m", time() -10800) . ".";
$curyear = "." . date("y", time() -10800) . "";
$result = mysql_query ("SELECT * FROM news WHERE Date LIKE '%$curmonth%' '%$curyear%' ORDER BY id DESC");
while($r=mysql_fetch_array($result))
{   
$Entry=stripslashes($r["Entry"]);
$ID=stripslashes($r["ID"]);
$Title=stripslashes($r["Title"]);
$Name=stripslashes($r["Name"]);
$Date=stripslashes($r["Date"]);
$Time=stripslashes($r["Time"]);
$Email=stripslashes($r["Email"]);

echo "<table width=435 cellpadding=0 cellspacing=0 class=blanktable><tr class=blanktable><td><a name=$ID></a><span class='header2'>$Title</span> by <a href='mailto:$Email'>$Name</a> on <span class='dates'>$Date</span> at <span class='dates'>$Time</span><br>" . nl2br($Entry) . "</td></tr><tr class=blanktable><td height=45 background='images/newsbottom.gif' class=blanktable></td></tr></table><br>";
}
?>
<?
} else {
?>
<?
$result = mysql_query ("SELECT * FROM news WHERE Date LIKE '%$month%' '%$year%' ORDER BY id DESC");
while($r=mysql_fetch_array($result))
{   
$Entry=stripslashes($r["Entry"]);
$Title=stripslashes($r["Title"]);
$Name=stripslashes($r["Name"]);
$Date=stripslashes($r["Date"]);
$Time=stripslashes($r["Time"]);
$Email=stripslashes($r["Email"]);

echo "<table width=435 cellpadding=0 cellspacing=0 class=blanktable><tr class=blanktable><td><a name=$ID></a><span class='header2'>$Title</span> by <a href='mailto:$Email'>$Name</a> on <span class='dates'>$Date</span> at <span class='dates'>$Time</span><br>" . nl2br($Entry) . "</td></tr><tr class=blanktable><td height=45 background='images/newsbottom.gif' class=blanktable></td></tr></table><br>";
}
?>
<?
}
?>
I have the form for going through the archives and I had to use an if statement for that, so sorry if that's messy. The page is http://www.thoughtriot.net/?z=news.php