Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cascading menus logic - I'm stuck

Status
Not open for further replies.

jimoblak

Instructor
Joined
Oct 23, 2001
Messages
3,620
Location
US
I'm seeking suggestions for where to head next...

I'm working on creating an online content management system that allows users to create articles and set them in categories. I use 2 MySQL tables for this now but would like to simplify this into one table.

The current system has a Categories table which is used to create a menu on the web page. There is also a table called Articles that populates subitems in the menu created by the Categories table.

Ex:

About Us (pulled from Categories table)
->History (pulled from Articles table)
->Contact Info
Products
->Apples
->Peaches

The new MySQL table design will have everything in one table:
id|parentid|subject
1|0|About Us
2|0|Products
3|1|History
4|1|Contact Info
5|2|Apples
6|2|Peaches

The single table will allow me to have subitems for the subitems:

7|5|Granny Smith
8|5|Red Delicious

So a menu could now look like:

Products
->Apples
->Granny Smith
->Red Delicious
->Peaches

I would prefer to expose subitems only when a parent item has been selected.

So here's the questions...

How would I use PHP to efficiently parse through all of the (possibly infinite) subnodes in this menu?

Can anyone recommend useful pre-built code? I found dozens of cascading menu classes at phpclasses.org but hope not to test each one.

An example of what I have started is at


- - picklefish - -

Why is everyone in this forum responding to me as picklefish?
 
There are a few things to consider - just think about them before you proceed:

I think you should incorporate some kind of ordering mechanism. How will you order the items in the menu table when you want to insert Jonagold in front of Granny Smith?

Keep the current parent items in a breadcrumb fashion. That will allow for only selected sub-items to display. Increment the level and expand only the selected ID.
Code:
$crumbs[0] = 2; Products
$crumbs[1] = 5; Apples
The top-level has 0 (zero) as the parentid. Just loop and follow the trail.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top