Answer the question
In order to leave comments, you need to log in
Displaying categories and their parents with a recursive SQL query?
In the Database there is such a construction: How to display a tree, from parents?
PS (output goes by php script via PDO to DOM on button click)
Answer the question
In order to leave comments, you need to log in
I found a good description of the problem on Habré .
And the actual solution that is needed on PhP
As far as I know - then one request with such a structure - no way. Here, either choose in this form and form a tree in the programming language, or use other ways to store tree structures in the database - nested sets, materialized path, adjusentcy list
If the database supports a recursive sql query, then you can use it, if mysql - you can use a stored procedure - stackoverflow.com/questions/16513418/how-to-do-the...
MySQL 8.0 is expected to support recursive subqueries. In the meantime, it's better to select everything and collect the hierarchy in your code. Moreover, the amount of data is small.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question