nullifi Posted October 23, 2007 Share Posted October 23, 2007 Greetings, I've been hurting my head for the past day or so trying to figure out how to do this. If anyone could give me any sort of advice to head me in the right direction I would appreciate it. I am trying to build a set of navigation links with sublinks from a db. The output I want would be something like: DogCatBird PuppyGarfieldTweety MaxKittenParrot I was thinking the db would something like: idtitleurlparent For the sublinks, and: id title url For the categories. I was considering grabbing the links via a select "where parent = ##". The place I am stuck at, is figuring out how to actually use this in order to properly output the links. My first thought was perhaps use nested for()'s. An array of an array of an array or something. Perhaps: $links[$a][$b]['title'] = 'Puppy'; $a would be the id of the header "Dogs", and $b would be a sort for the row containing "Puppy". for($a = 0; $a <= mysql_num_rows($category_query); $a++) { echo $category['title']; // And assorted other html's for($b = 0; $b <= mysql_num_rows($sublinks_query); $b++) { echo $category[$a][$b]['title']; // etc. } } This seems very, messy, to me. Perhaps its not, what do I know. Is this the way I should be going, or is there a simpler easier, more efficient way I don't know about? Thanks for any input. Quote Link to comment https://forums.phpfreaks.com/topic/74513-advice-on-how-to-build-navigation-links-from-db/ Share on other sites More sharing options...
teng84 Posted October 23, 2007 Share Posted October 23, 2007 can you print your array eg... echo '<pre>'; print_r($category); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/74513-advice-on-how-to-build-navigation-links-from-db/#findComment-376591 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.