0

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?

4
  • Run another query in each while loop...? Commented Aug 8, 2012 at 17:09
  • That's what i initially used to do , but i was told to do it this way in another post , but i dont understand how to .... Commented Aug 8, 2012 at 17:14
  • do you remember the link to that post? Commented Aug 8, 2012 at 17:22
  • @victoroux check below -sorted out Commented Aug 8, 2012 at 17:42

1 Answer 1

2

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];
}
Sign up to request clarification or add additional context in comments.

1 Comment

my replies record set will return 4 rows, and if i was in the while loop at the point where i was displaying the replies for comment 3 , i would only like to dispaly 3 of the records from the result where they match the commentID

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.