php mysql显示结果集中的选定记录

I have a query which fetches replies to comments. so my first query has them comments, e.g.

comment 1 <BR>
  &nbsp; reply 1<BR>
comment 2<BR>
comment 3<BR>
   &nbsp; reply 1<BR>
   &nbsp; reply 2<BR>
   &nbsp; reply 2<BR>

Comment 3 has 3 replies. I make one query to fetch all replies from my database where the commentID in (1,2,3) . This will bring me all valid replies.

Now the problem is when I want to display the results, I start a while loop and go through all the comments.

How do I get the selected replies just for that particular comment while in the while loop?

Assuming you stored the replies in a multidimensional array lets say $array_replies, this is how youd do it

for ($i=0; $i<count($array_replies[$commentID]); $i++) {
   echo $array_replies[$commentID][$i];
}