G
G
GilbertAmethyst2020-07-31 12:13:35
PHP
GilbertAmethyst, 2020-07-31 12:13:35

How to make an algorithm for displaying dropdown lists?

Hello!

I have a database with a table like this:

Id | Title | Path
1 | Главное | /
2 | Новости | /1
3 | О нас | /1
4 | Новости о спорте | /1/2
....
1231 | Спортивное питание | /1/2/621/521/531/251
и т.д


It stores dropdown lists with unlimited nesting. The path to the item lies in the Path column, where the Ids of the parent items are indicated.
After getting the rows from the database, I want to display dropdown lists on the page, for which it would be convenient to get a multidimensional array reflecting the location of the items and the algorithm to display them on the page.

I can not think of a normal algorithm to do this. How would you do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2020-07-31
@GilbertAmethyst

Add parent_id column
select all data
build tree and pass to template engine

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question