B
B
BonBon Slick2016-10-21 16:05:41
PHP
BonBon Slick, 2016-10-21 16:05:41

Displaying categories and their parents with a recursive SQL query?

In the Database there is such a construction: b91e01942cbf4307984be559140cd285.pngHow 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

4 answer(s)
B
BonBon Slick, 2016-10-21
@BonBonSlick

I found a good description of the problem on Habré .
And the actual solution that is needed on PhP

A
Anton, 2016-10-21
@sHinE

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

I
iegor, 2016-10-21
@iegor

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...

C
ComodoHacker, 2016-10-21
@ComodoHacker

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 question

Ask a Question

731 491 924 answers to any question