I’m creating a commenting system with reply functionality and I’ve seen to run into an issue.
Comments table
id post_id comment replyTo 0 17 Blah 2 1 17 hello 2 2 17 goodbye 3 17 great 1 4 17 bad
My code
$comments = mysql_query("SELECT * FROM comment WHERE post_id='$post_id' ORDER BY id DESC");
while($comment = mysql_fetch_assoc($comments))
{
$id = $comment['id'];
$comment = $comment['comment'];
$reply = $comment['replyTo'];
echo $comment;
echo "<br />";
$replyQuery = mysql_query("SELECT * FROM comment WHERE replyTo='$id' ORDER BY id DESC");
while($comment = mysql_fetch_assoc($comments))
{
$id = $comment['id'];
$comment = $comment['comment'];
$reply = $comment['replyTo'];
echo $comment;
echo "<br />";
}
}
My result
Blah
great
hello
goodbye
blah
hello
great
bad
intended result
goodbye
blah
hello
great
bad
THANKS!!!!!
}
?>