0

I wasnt sure what to label this so here we go.

I have a table which holds messages sent by users. The first message sent is the parent and then each message after that is a reply. However a reply can have a reply, and a reply to a reply can also have a reply...and so on. The table structure is:

message_id   message   reply_messages_id
1            abc       0 (this means its the parent)
2            def       1 (reply to message_id 1)
3            ghi       2 (reply to message_id 2)
4            jkl       1 (another reply to message_id 1)
5            mno       3 (reply to message_id 3)
6            pqr       0 (another parent)
7            stu       6 (reply to message_id 6)

The thing I am struggling with is that I am trying to have the output displayed as:

abc
- def
  - ghi
    - mno
- jkl
pqr
- stu

The other thing is I dont know how many layers deep a reply can go as a user can keep replying to replies.

ANY help is greatly appreciated.

ajreal
  • 46,720
  • 11
  • 89
  • 119
puks1978
  • 3,667
  • 11
  • 44
  • 103
  • Try this... http://stackoverflow.com/questions/10215980/categories-with-sub-php-mysql/10244518#10244518 – Vaishu Jun 04 '12 at 10:12
  • What you need simple recursion to build your output. Possible duplicate of [Recursive function to generate multidimensional array from database result](http://stackoverflow.com/questions/8587341/recursive-function-to-generate-multidimensional-array-from-database-result) – deceze Jun 04 '12 at 10:25
  • @Kere Puki - Thanks.. This is same type using menu script.. http://hiox.org/33272-php-db-based-menu-script.php – Vaishu Jun 04 '12 at 11:08

1 Answers1

0

I litterally just answered one similar to this about a week ago... it generates the output as a stored procedure including indentation... The principles would be almost identical, just slight change in the column names of data.

Other answer posted

Community
  • 1
  • 1
DRapp
  • 47,638
  • 12
  • 72
  • 142