php - Having some trouble with a mysql query pulling data from multiple tables... logic question -


Ill try to keep this simple and point-to-point basically I have news feeds and a comment section. There are two levels in the section of the comments: responses and then responses to responses. Originally structured like a special newsletter:

  -> Comment --- & gt; Answer --- & gt; Answer:   

There may be many answers in each comment, obviously for doing this, to answer incorrectly, you have to do an SQL query for each comment and to list them. Edit Comments have only 1 response level, that is, can not answer the answers. - Thanks Johnp

My questions for this kind of query:

Should I have comments and answers in different tables and should use a join, or do I answer Can I keep comments and use the qualifier to separate the same table and type?

Should I try sorting them using the query or drag all the data into an array and sort? Display this way?

My table currently is as follows:

  ID (unique, auto increment) NEWS_ID (comment on a special news post is concerned) REPLY_ID (if any If there is an answer to another comment, please comment on a parental comment) USER_ID BODY PUBLISHED_DATE   

My suggestions will be highly appreciated by those wise people! I am still in the initial stages of fully understanding JOINS and other high level MySQL query structures. (IE: I have to suck on my SSX, but learning IIM :)

Since you have replied that One level is deep ..

I can create comment 1 table and link a comment_id field and link a news_id field to news item To show. In this way you can simply query for all comments that match news_id and sort it by comment_id . And then a small fraction of PHP array magic will give you a sorted list of comments / answers.

So take a look at your current table, you are on the right track.

Comments