Hi there,
I am making a forum section for my website.
I am currenly in the process of making the 'display topics' file that basically lists all of the threads in order of when they where last modified/replied to.
I figured, the most probable way of doing this, is to just select the top most rescent posts/replies directly from the database...
I could then use an if() statement to find out if the post was a 'reply to a topic' or not...
if it wasnt... query the database for the posts 'parent' details and echo() them instead of the reply details.
I have had a go at it (below), but it doesnt seem to be working.
It prints out some results fine (no parse errors etc!), however the wrong ones. It seems to echo ALL of the results for the query, ignoring the if($parent_replyid != 0) { line within the while loop.
Any ideas?
Code is below!
$result = mysql_query("SELECT * FROM `posts` WHERE `forumid` = '$cat_id' ORDER BY sticky DESC, date DESC", $db) or die ("Error Executing Query");
// Echo results
while ($data = mysql_fetch_array($result)) {
$parent_replyid = $data[replyid];
if($parent_replyid != 0) {
$parent_query = mysql_query("SELECT * FROM `posts` WHERE `id` = '$parent_replyid'", $db) or die ("Error Executing Query");
$parent = mysql_fetch_array($parent_query);
}
echo "Posted By:"; if($parent_replyid != 0) { echo $parent[username]; } else { echo $data[username]; } echo "<br>";
echo "Subject:"; if($parent_replyid != 0) { echo $parent[subject]; } else { echo $data[subject]; } echo "<br>";
echo "Message:"; if($parent_replyid != 0) { echo $parent[message]; } else { echo $data[message]; } echo "<br>";
echo "Date: "; if($parent_replyid != 0) { echo date('M jS Y, g:i a',$parent[date]); } else { echo date('M jS Y, g:i a',$data[date]); } echo "<br><br>";
}
Thanks!