views:

45

answers:

3

What is the best way of implementing multi-level lists/bullets in php?

What I'm trying to implement is a system to take in short phrases, and categorize them within sections. However, at the same time, I would like to have each section to be collapsible and capable of having sub-sections within them.

For Example: Section 10
Section 10.X
Section 10.X.X

I was thinking of having each sub-layer as an array, but I realize that I've seen the same type of collapsibility in many places, and they all seem to be similar. Maybe there already is a package or library that does this? And if there is, how should my data-structure for keeping each entry be structured?

A: 

Your bullets are being done in HTML, as PHP merely generates HTML code. Consider using nested <ul> tags.

The collapsing is most probably going to be javasscript. (Although I wonder if the CSS :active psuedoclass would work in supportive browsers...)

Regarding the package, I'm not sure. You essentially need a recursive list generating function.

Moshe
What would be the best way of storing this on the server-side? Nested Arrays?
Sakamoto Kazuma
That might work. Nested Arrays are called "Multi-dimensional" arrays. I'm no expert. Just pointing out that you're not just focusing on PHP here... Also, Sarfraz has a point with Tree View, although I'm not sure what it is.
Moshe
A: 

For the kind of structure you mentioned, i think you need what is know as Tree View. Check it out on how to implement that.

Screenshot:

alt text

Sarfraz
A: 

Anything to do with toggling, display lists, indenting etc should be achieved relatively easily with HTML/CSS/Javascript.

Inside your category table, you could create a parent_id field which matches to your primary ID. Then run loops to display your TLD as well as another loop to display the categories within the parent.

Stoosh