Relational databases do not lend themselves easily to tree structures. If you only have id
and parent_id
fields, you’ll have to do a lot of looping and recursion to work with trees. That’s why Nested Sets or MPTT were invented. You should move to that model for your trees and this question will solve itself.
2
solved Delete record from php mysql in hierarchical manner [closed]