Jump to content

Making a menu from an array of URL's in a DB


rpmorrow

Recommended Posts

Hi,

 

I'm wanting to make an <ul> type menu based on info in a database.

 

Each DB entry has a page URL, and page title among other info.

 

I somehow need to loop through the database and fill some arrays in a way that structures the urls for a menu.

 

The menu structure would be the same as the directory structure. For example;

 

Level One Index (index.htm)

      SubLevel One (somepage.htm)

      SubLevel Two (someotherpage.htm)

            SubLevel Three Index (/sub/index.htm)

                  SubLevel One (/sub/somepage.htm)

 

Can I sort data in PHP by its path depth, or do I need to count slashes? I feel a bit confuse at where to start  :-[

 

Cheers

 

The info is in a database. Each row has the following data. "id", "parent_id", "title", "url", "content"

 

"id" is a unique numerical key

"parent_id" is the page 'above' this one

 

There could be any number of parents and children as the site content would change over time (hence the need for a dynamic menu).

 

I'm sure it is not too tricky, I just seem to be suffering from a mental logic block  :-[

 

Does this make sense?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.