Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Indented Comments?

Status
Not open for further replies.

alphacooler

Programmer
Aug 29, 2005
73
US
I'd like to figure out how to setup a commenting system that indents one level deep (ala Digg style). So each comment has a "reply" link and if clicked the new post goes right under the other (no matter what date).

So the problem is how would you setup a query to order posts like that? Order by date, then what?

Thanks so much. This problem seems a bit intractable.
 
You give each original post an ID and then the posts that belong to that comment have the same ID in another field to link to.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Vacunita,

I think I see what you mean, but I am going to need to be able to work with the reply post (I need to be able to identify it so I can indent it). How would I do that? I can get them to order just fine using your tip, but I need to be able to say "ok, this is a reply, indent it".

Thanks so much.
 
Simple when you query for the replies if it has an ID in the reply field then its a reply, so you indent it. Basically you would need to run a query for all posts that have a specific ID in their reply fields then you know they are replies to a post with a certain ID.





----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
So to output a particular thread, I would need to do one giant query ordered by date, then run a query for every single post checking if there are any posts with the same ID in the reply field?

Is there another way? Isn't embedding a select inside a loop a bit dirty?
 
Wow!! Back from the dead.

You might be able to do it in a single query with joins. but then we are deviating from this forums scope, and so you would need to ask this in the forum for whichever DB you are using.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
this probably is a sql question but since i've given it a bit of thought when re-reading it: here's my ten pence worth;

create a column for the thread ID and for each post (postID)
also create a column to store the postID that a post replied to.

so the table would have
Code:
postID (autoincrement)
threadID (random or foreign key)
title (if you allow a separate title per post otherwise i'd go the foreign key route and store the title in the other table with the threadID)
userID (foreign key to the users table)
inreplyTo (the postID)
posttext (longtext)
timestamp

then you do a single query on the threadID ordered by date ascending, inReplyTo ascending

grab all the results into an array
then recursively iterate over the array examining the inReplyTo field.

 
BACK from the dead (AGAIN!).

After starting this thread I tried to get this to work with jpadie's method, but I couldn't quite get it.

Well I have a new project I would like to definitely use this on. So perhaps Jpadie or somebody else could explain the last post for me.

So I query by date desc, then spit into an array. I loop through the array outputting each post in order...but *somehow* I need to search every post for other posts that have that postID in their inreplyTo field. I'm not sure how to go about that at all.

If somebody can figure this one out, I will name my first born after you. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top