I am trying to make a threaded message board.
$result = mysql_query("SELECT * FROM message WHERE parent='0'");
while($r=mysql_fetch_array($result))
{
$posttitle=$r["title"];
$date=$r["date"];
$topic=$r["id"];
$parent=$r["parent"];
$author=$r["author"];
$result2 = mysql_query("SELECT * FROM message WHERE parent='$topic' AND parent!='0'");
while($r2=mysql_fetch_array($result2))
$posttitle2=$r2["title"];
$date2=$r2["date"];
$topicid2=$r2["id"];
$parent2=$r2["parent"];
$author2=$r2["author"];
echo "<a href=\"index.php?section=fans&page=board&topic=$topic\">$posttitle</a>";
echo "<br><a href=\"index.php?section=fans&page=board&topic=$topicid2\">$posttitle2</a>";
}
echo "<P>";
With that, it is never finding the $topicid2 for the replies. Its also not running the whole script as a while. I added a second topic and it shows the second topic right next to the original topic and the replies.
More sense:
Test
Replytestnewtopic
Replytest
"Test" is a topic (id: 1)
"replytest" is a reply to topic 1
"newtopic" is a new topic. With no replies
"Test" (original topic) had 2 replys but only showed the later one.
Please help.