• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Printing comments - Help needed

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,

I want to display some text and the database table that I have to store these text is like this, TId is the TextId and RId is the referenceId.

TId RId
1
2 1
3 2
4
5 1

Now, the actual text will come from some other table. I want to display them in my code like this

1
2 (replied for 1)(one indendation in the web page)
3 (replied for 2)(two indendations in the web page)...and goes on
5 (replied for 1)(one indendation in the web page)

How can I acheive this?
[ January 10, 2008: Message edited by: Jothi Shankar Kumar Sankararaj ]
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to display something similiar to this

If you go that page scroll to the middle of the page and you will see something that says Threaded replies in a square box and I'm trying to devise a logic similiar to that.

Any idea guys???
[ January 10, 2008: Message edited by: Jothi Shankar Kumar Sankararaj ]
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic