Jump to content

PHP Navigation For CMS


scraptoft

Recommended Posts

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
-subcategory
Category2
-subcategory
-subcategory
Category3
-subcategory
-subcategory
-subcategory
-subcategory

Heres 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:
Category1
Category2
Category3

I 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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.