S
S
Sergey Koval2015-02-02 11:44:09
PHP
Sergey Koval, 2015-02-02 11:44:09

I do not understand how to organize the output of material from the database?

Hello.
This is my first time building a website from scratch. And I ran into this problem.
You need to create a page with multi-level categories.
About like here .
I don't know if this is correct, but I created two such tables.
https://www.dropbox.com/s/k5h41avzixcssbi/%D0%A1%D...
And now I don't know how to implement all this. I've been googling all morning, nothing sensible. I even managed to order a book)
Help please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Gamega, 2015-02-02
@gadfi

Not the most successful version of a multi-level tree, but the easiest. If there are not many levels, or operations with all descendants are not needed, then it is quite viable
what exactly does not work out and what is the task?
PS in the book programming sql databases typical errors and their elimination, this task is described in more detail
to make it clearer, simplify the table, add everything you need
─────────────
1 | 0 |CATEGORY1
2 | 1| category1.1
3 | 1 | category 1.2
4 | 3 | category1.2.1
5 | 0 | CATEGORY2
6 | 5 | category2.1
.......
to get the list of categories
select *from categories where parent_id = 0
the user clicked on category one, got id 1 expand the tree
select *from categories where parent_id =1 The
disadvantage is that we cannot get all the children of CATEGORY1 at once and we don’t even know without an additional query if they have children elements (for example, which element is category 1.2), but for your task when the depth is not very large, it’s quite possible

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question