Hello, the first time I come across such a sample. In general, there is such a user table.

  • id - user id
  • name - username
  • parent_id - link to parent record ID

I need to pull out from the database all users whose parent_id is equal to the current user id .

Then where parent_id is equal to their id and so endlessly until the chain ends. How to do it better?

  • one
    Recursion, no? good articles on this topic habrahabr.ru/post/46659 habrahabr.ru/en/post/153861 - Pavel Dura
  • one
    If the table is not large, then you can shove everything into an array and already pull it from the array, so as not to contact the database many times - Yoharny Babay
  • Yes, not big, so I am going to do) - bemulima

0