A
A
Alexander2016-03-18 18:01:03
PHP
Alexander, 2016-03-18 18:01:03

How to make a menu with categories?

Colleagues, hello, please don't kick me :)
I'm doing a test project for myself and faced with the creation of a menu of categories. I can make a normal menu, that is, when all the children are displayed at once, but how can I make the child appear only when the parent is clicked?
For example, initially we have two parent categories:
- Shooters
- Sports
When you click on shooters, it was like this, the ID of the clicked category is displayed in the get parameter:
- Shooters
--First-person
--Third- person
-Sports
"their descendants were bred, etc.
I don't understand how to implement this...
The table in the database looks like
id,id_parent,name
I know what can be done with js, display all categories and make an accordion through js, but how to do it only in php? Thank you all very much!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
6
65536, 2016-03-18
@65536

store somewhere in the session the state of node deployment, an array of ids. decide which default state for everyone, when rendering the menu, take into account the presence of an id in this array, if so, consider the state opposite to the default one. if it turns out that the nested tree is hidden, then do not render it at all or make it hidden. when you click on the nodes, send information to the server that such and such a node changes state, change it in the session (remove or add to that array), reload the tree. Or don't reload? and jsom fold it and lay it out, provided that it was completely loaded, along with hidden nodes
and only not id_parent, but parent_id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question