posted 17 years ago
I'm assuming that you want, from your example:
What about something like:
- Get the first tID.
- Call recursive method printPost(tID)
The method printPost(tID) would then:
- Print the text associated with tID
- Look for any records where rID = this tID
- For each of the above records, print an indent, then get THEIR tID and recursively call printPost(tID) (with the new tID).
- If there aren't any such records, just go on to the next tID.
I guess you'll probably also want to keep track of which tID's you've already printed, as responses to previous tID's, so you don't print each piece of text more than once (unless that's your intention, of course). For example, I guess you don't want:
So you need a record of the fact that you printed 2, 3 and 5 under 1, to avoid printing them again further on.
Sorry - that's probably not particularly clear, but I think it's how I'd approach it...
Cheers,
Dave.