rpmorrow Posted January 14, 2010 Share Posted January 14, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188498-making-a-menu-from-an-array-of-urls-in-a-db/ Share on other sites More sharing options...
lemmin Posted January 14, 2010 Share Posted January 14, 2010 I think the best way to go about this is to have all of that information in your database if it isn't already. Can you explain in more detail how your database is set up? Quote Link to comment https://forums.phpfreaks.com/topic/188498-making-a-menu-from-an-array-of-urls-in-a-db/#findComment-995141 Share on other sites More sharing options...
waynew Posted January 14, 2010 Share Posted January 14, 2010 You need to read http://dev.mysql.com/tech-resources/articles/hierarchical-data.html Quote Link to comment https://forums.phpfreaks.com/topic/188498-making-a-menu-from-an-array-of-urls-in-a-db/#findComment-995159 Share on other sites More sharing options...
rpmorrow Posted January 15, 2010 Author Share Posted January 15, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/188498-making-a-menu-from-an-array-of-urls-in-a-db/#findComment-995758 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.