A
Anonymous
Guest
I'm trying to build an extremely simply bulletin-board system, and it doesn't work. I've debugged it pretty well.
This is how it works: you post a message, and the Topics table has a Topic_id field that auto_increments. Then, the Replies table has a field, Topic_ref_id, which contains the Topic_id of it's parent topic. When the topic list page is generated, the link to follow into each topic contains a HTTP GET query string. The link generally looks like this
Now, the script for viewtopic.php is where the problem is. It doesn't work, even though I have a row in the Replies table, with Topic_ref_id 1, and in the Topics table, I have a row with Topic_id 1.
It doesn't display the reply, for reason's unknown. Any thoughts?
This is how it works: you post a message, and the Topics table has a Topic_id field that auto_increments. Then, the Replies table has a field, Topic_ref_id, which contains the Topic_id of it's parent topic. When the topic list page is generated, the link to follow into each topic contains a HTTP GET query string. The link generally looks like this
Code:
<a href="viewtopic.php?msg=<?php echo $Topic['Topic_id']; ?>"><?php echo $Message['Title_link_text']; ?></a>
It doesn't display the reply, for reason's unknown. Any thoughts?
Code:
<?php
$M_Conn=mysql_connect ("localhost","root","some_pass");
mysql_select_db ("forum",$M_Conn);
$SQL="
SELECT Title,Poster,Message,Topic_id
FROM Topics
WHERE Topic_id=" . $_GET['msg'] . ";
";
$Result=mysql_query ($SQL,$M_Conn);
$Message=mysql_fetch_array ($Result);
?>
<html>
<head>
<title> View topic - <?php echo $Message['Title']; ?> </title>
</head>
<body>
<i><h1> Topic: <?php echo $Message['Title']; ?> </h1>
Posted by: <?php echo $Message['Poster']; ?>
<br><br>
Message:</i><br>
<?php echo $Message['Message']; ?>
<br><br>
<?php
$SQL="
SELECT Message,Poster,Topic_ref_id,Reply_id
FROM Replies
ORDER BY Reply_id DESC
WHERE Topic_ref_id=". $Message['Topic_id'] .";
";
$Result=mysql_query ($SQL,$M_Conn);
while ( $Reply=mysql_fetch_array ($Result) )
{
?>
<i>Poster: <?php echo $Reply['Poster']; ?><br>
Message:</i><br>
<?php
echo $Reply['Message'];
}
mysql_close ($M_Conn);
?>
</body>
</html>