By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,558 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,558 IT Pros & Developers. It's quick & easy.

threaded comments

P: 33
so i\'ve been trying to build a threaded comments section on my website, with little to no luck trying to figure out how to loop through 2 while loops and load my comments. i\'ve read a lot of different code snippets and comments about this, and seem to get further lost.. here is what im attempting, mysql database looks like this
id
profile_id
parent
type " 'a', 'b' "
comment
datetime
so far ive tried doing it with one query and one loop, and 2 queries and 2 loops, and i only ever get errors or just one parent and one child.... and i have many parents and many children, but children are only one deep... i dont necessarily need the answeres or someone to do this for me, but maybe someone know a good easy to understand tutorial i can go through to help me unserstand... thanks
Dec 1 '11 #1

✓ answered by Rabbit

I suppose you would do something like this
Expand|Select|Wrap|Line Numbers
  1. sql = "select parents from comments"
  2.  
  3. for each row in sql
  4.    output sql.comment
  5.    sql2 = "select children from comments where parent = " + sql.parent
  6.  
  7.    for each row in sql2
  8.       output sql2.comment
  9.    next
  10. next

Share this Question
Share on Google+
7 Replies


Rabbit
Expert Mod 10K+
P: 12,359
Can you post an example of what you mean by threaded comments?
Dec 1 '11 #2

P: 33
I'm not on my computer right now so hope this can help clarify. If not I can try posting some code.
By threaded comments I'm talking about comments people leave for others. I hate to say it. But. Like facebook. Or better yet like YouTube. Structured like this
Parent
Child
Child
Parent
Parent
Child
Dec 2 '11 #3

Rabbit
Expert Mod 10K+
P: 12,359
Can't a child also be a parent?
Dec 2 '11 #4

P: 33
In some instances they can be. But for what I'm tryingto do I don't want children to be parents
Dec 2 '11 #5

Rabbit
Expert Mod 10K+
P: 12,359
I suppose you would do something like this
Expand|Select|Wrap|Line Numbers
  1. sql = "select parents from comments"
  2.  
  3. for each row in sql
  4.    output sql.comment
  5.    sql2 = "select children from comments where parent = " + sql.parent
  6.  
  7.    for each row in sql2
  8.       output sql2.comment
  9.    next
  10. next
Dec 2 '11 #6

P: 33
thats it... thank you so much. i tweaked it a little but thats it, and its working great... :D
Dec 3 '11 #7

omerbutt
100+
P: 638
you must select the right answer to the question if you think he has provided you with the solution , so that this could be helpful to any one else who comes here googling.
regards,
Omer Aslam
Dec 3 '11 #8

Post your reply

Sign in to post your reply or Sign up for a free account.