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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Navigation bar for a store

Status
Not open for further replies.

oohoohoohooh

Programmer
Apr 30, 2005
55
GB
Hi, I wish to create a navigation bar for users to follow as they browse a store I am creating. The following is the table structure for the categories table:

- cat_id
- subcat_id (if 0 then not a subcat)
- cat_name

This allows me to have unlimited subcats. An example of some values are

1 | 0 | Music, Video
2 | 1 | Music
3 | 1 | Video
4 | 2 | Classical
5 | 2 | Rock, Pop
6 | 5 | Rock
7 | 5 | Pop

Then the navigation bar (for the pop category) would be:

Music, Video -> Music -> Rock, Pop -> Pop

How would I generate such a navigation bar without having to do loads and loads of sql queries. I'd appreciate your help. Thanks
 
When you're talking about hierarchical data, you're going to have some kind of recursion.

That recursion may be of the form of multiple SQL queries, each fetching the parent of the one previous iteration.

That recursion may be of the form of fetching the entire hierarchy from the database, storing it in array and recursively searching through the array for the "trail of breadcrumbs" you're trying to create.

Each method has its strengths and weaknesses. I'd probably go with the "lots of SQL queries" method. Processing queries and returning data quickly is what an RDBMS exists to do.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top