i am having trouble with my php code where i want to display all the topics from mysql database but it don't display anything and just echo's he posts could not be displayed, please try again later. could someone advise me about what i am doing wrong here thanks. session is in header.php
<?php
include 'mysql.php';
include 'header.php';
//retrieving basic data from topic
$sql = "SELECT
id,
subject
FROM
topics
WHERE
id = ". mysql_real_escape_string($_GET['id']);
$result = mysql_query($sql);
if(!$result)
{
echo 'The topic could not be displayed, please try again later.' . mysql_error();
}
else
{
if(mysql_num_rows($result) == 0)
{
echo 'This topic dose not exist.';
}
else
{
while($row = mysql_fetch_assoc($result))
{
//display post data
echo '<table class="topic" border="1">
<tr>
<th colspan="2">' . $row['subject'] . '</th>
</tr>';
}
//fetch the posts from the database on post.postby = users.id tells us that these are both the same through left join.
$sql = "SELECT
users.id,
post.content,
post.date,
post.topic,
post.postby,
users.username
FROM
post
LEFT JOIN
users
ON
post.postby = users.id
WHERE
post.topic = " . mysql_real_escape_string($_GET['id']);
$result = mysql_query($sql);
if(!$result)
{
echo '<tr><td>The posts could not be displayed, please try again later.</tr></td></table>';
}
else
{
while($row = mysql_fetch_assoc($result))
{
echo '<tr class="topic-post">
<td class="user-post">' . $row['username'] . '<br/>' . date('d-m-Y H:i', strtotime($row['date'])) . '</td>
<td class="post-content">' . htmlentities(stripslashes($row['content'])) . '</td>
</tr>';
}
}
if(!$_SESSION['loggedIn'])
{
echo '<tr><td colspan=2>You must be <a href="signin.php">signed in</a> to reply. You can also <a href="signup.php">sign up</a> for an account.';
}
else
{
//show reply box
echo '<tr><td colspan="2"><h2>Reply:</h2><br />
<form method="post" action="reply.php?id=' . $row['id'] . '">
<textarea name="reply-content"></textarea><br /><br />
<input type="submit" value="Submit reply" />
</form></td></tr>';
}
//finish the table
echo '</table>';
}
}
include 'footer.php';
?>