A
A
Andriii87782017-08-31 09:25:43
PHP
Andriii8778, 2017-08-31 09:25:43

How to write a post wall recursion?

Display messages in the form of a tree. There are 2 arrays. ($messages - messages, $comments - comments to messages and comments to comments) If there were only messages and comments to them. It's just foreach with conditions and everything is simple. And you need more comments to the comments and so on. Not without recursion. With simple recursions, everything is clear, but there is no such experience to write, and even the brains of the campaign. Can someone suggest something. Or someone did the same.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vyacheslav Barsukov, 2017-08-31
@slavabars

Make the parent field and write the comment parent.
Then a recursion function that checks if there are messages in the parent field is the id of this message. And so with each nested message

message($id);

function message($id){
     /* получаем сообщение, возвращаем id сообщения в бд*/
     echo сообщение;
     /*select ид родителя = ид с базы сообщения*/
     foreach (найденные сообщения){
          message(id):
     }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question