scraptoft Posted June 22, 2006 Share Posted June 22, 2006 I am trying to create a navigation bar which will echo all of the categories in the database.I want the navigation bar to show like below:Category1-subcategory-subcategory-subcategoryCategory2-subcategory-subcategoryCategory3-subcategory-subcategory-subcategory-subcategoryHeres my code to query Category:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$query_category = "SELECT name FROM webstructure where level = '2'"; $result_level = mysql_query($query_category) or die("Invalid query: " . mysql_error()); while ($row=mysql_fetch_array($result_lcategory2)) { $name = $row['name'];[/quote]This echos like:Category1Category2Category3I cannot figure out how to echo the correct [b]Subcategory[/b] underneath it's speficific [b]Category[/b]. Does anyone have any ideas how to do this, or what functions to use?Thankyou for your time Quote Link to comment https://forums.phpfreaks.com/topic/12601-php-navigation-for-cms/ Share on other sites More sharing options...
trq Posted June 22, 2006 Share Posted June 22, 2006 Depends on how your data is related really. More than likely you would need to use recursion.can we see your table schema? Quote Link to comment https://forums.phpfreaks.com/topic/12601-php-navigation-for-cms/#findComment-48312 Share on other sites More sharing options...
scraptoft Posted June 22, 2006 Author Share Posted June 22, 2006 My category table is like so.Name [name of category or subcategory]parent_category [if its a subcategory the parent name is here]level ['1','2','3'] [different levels to show on each page]After writing this out, i'm starting to think I need to make changes to my table. Or can I get away with it this way?Cheers for your fast reply. Quote Link to comment https://forums.phpfreaks.com/topic/12601-php-navigation-for-cms/#findComment-48317 Share on other sites More sharing options...
trq Posted June 22, 2006 Share Posted June 22, 2006 You could get away with it but there are better ways to represent hierarchical data. Maybe [a href=\"http://www.phpriot.com/d/articles/php/application-design/nested-trees-1/index.html\" target=\"_blank\"]this[/a] tutorial will help. Quote Link to comment https://forums.phpfreaks.com/topic/12601-php-navigation-for-cms/#findComment-48322 Share on other sites More sharing options...
scraptoft Posted June 22, 2006 Author Share Posted June 22, 2006 I'm still trying to learn PHP but could do with this project finished (it doesn't have to be perfect) so I can get onto studying the language more. Could you give me a few pointers on how I could get away with it.p.s thanks for the tutorial I will deffinatly read it more indepth in the morning. Quote Link to comment https://forums.phpfreaks.com/topic/12601-php-navigation-for-cms/#findComment-48327 Share on other sites More sharing options...
scraptoft Posted June 22, 2006 Author Share Posted June 22, 2006 [b]b[/b]u[b]m[/b]pAnyone can shed some more light on this problem? Quote Link to comment https://forums.phpfreaks.com/topic/12601-php-navigation-for-cms/#findComment-48473 Share on other sites More sharing options...
freakus_maximus Posted June 22, 2006 Share Posted June 22, 2006 Check out my post here:[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=94066&st=0&p=376462entry376462\" target=\"_blank\"]Catagories and Subcatagories[/a]This has helped a few others out and should get you going the way you want. Quote Link to comment https://forums.phpfreaks.com/topic/12601-php-navigation-for-cms/#findComment-48502 Share on other sites More sharing options...
scraptoft Posted June 22, 2006 Author Share Posted June 22, 2006 Cheers mate, i'm finding that post very helpful. I'm 80% to the way I want it, another hour or so and it should be working great.Cheers guys Quote Link to comment https://forums.phpfreaks.com/topic/12601-php-navigation-for-cms/#findComment-48527 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.