Jump to content

Left Navigation coding - more depth to navigation bar


Matt B

Recommended Posts

Hi,

 

I am am looking to develop further the code below. This code allows me to display a left navigation bar with Main Links and then if you click a Main link, that link is listed first in the list and its' submenu appears below. For the majority of links in the navigation bar this is fine. But for about 2 of the Main links this basic navigation is not suitable.

 

I need the navigation for 2 of the links to offer more depth. So, for example, if you click Accessories in:

 

Shoes

Trousers

Shirts

Accessories

 

Looks like this if Accessories is clicked:

 

Accessories

Belts

Cuff Links

Wallets

Shoes

Trousers

Shirts

 

Looks like this if belts is clicked (Main link name changed and submenu changed):

 

Accessories - Belts

Brown leather

Black Leather

Multicolour Designs

All casual

All formal

Shoes

Trousers

Shirts

 

Looks like this is Brown Leather is clicked:

 

Brown Leather Belts

Armani Brown Leather Belt 32"

Armani Brown Leather Belt 34"

Hugo Boss Brown Leather Belt 32"

Hugo Boss Brown Leather Belt 34"

Shoes

Trousers

Shirts

 

 

Currently the code does not allow for this depth in the navigation bar. Any ideas how it could be done? Do I need additional tables for each subcategory. How do I ensure the category clicked does not appear in the rest of the navigation bar, as in the code I have at the moment?

 

Currently the code is:

 

 

$res = mysql_query("SELECT * FROM categories");

while($row = mysql_fetch_array($res)) {

  $cats[$row['categoryid']] = $row['categoryname'];

}

if(isset($_GET['category'])) {

$selcat = $_GET['category'];

}

if(isset($_GET['product'])) {

$prod_info = mysql_fetch_array(mysql_query("SELECT * FROM products WHERE productid = ".$_GET['product']));

//Prod_Info now gets stored for use in the main display.

$selcat = $prod_info['categoryid'];

}

if(isset($selcat)) {

  echo "<a href='categorylist.php?category=".$selcat."'>".$cats[$selcat]."</a>";

  unset($cats[$selcat]); //Gets rid of it for later.

  $res = mysql_query("SELECT productid,name FROM products WHERE categoryid = ".$selcat);

  while($row = mysql_fetch_array($res)) {

  echo "<a href='product.php?product=".$row['productid']."'>".$row['name']."</a>";

  }

}

foreach($cats AS $key => $cat)  {

  echo "<a href='categoryview.php?category=".$key."'>".$cat."</a>";

}

 

 

 

Thank you for looking at this post,

 

Matt.

 

Link to comment
Share on other sites

have you considered using nested lists and using either suckerfish css menus, or a jquery accordian menu?

 

that way you have all the menus listed in once go, and the css or javascript makes it all operational. it would not account for pushing the current choice to the top of the list though

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.