Jump to content

Navigation Menu


Sharky01276

Recommended Posts

Ok im getting my self really confused i think im thinking way to complicated about this. Basically i want a very simple navigation menu with multiple levels eg.

 

PHP

About

History

Syntax

  String

  Integer

  Arrays

Mysql

About

History

  Versions

    5.1

    5.2

Syntax

 

So when php is clicked the next set of options is shown. Then when Syntax is show the next options are shown. Im quite happy for the page to be reloaded to do this. For the life of me i cant think of the way of doing this. Ive tried using trees and nodes but im getting my self confused.

 

Any help would be appreciated thanks

 

Alan

Link to comment
Share on other sites

i made this a while ago... maybe ya can find it useful to look at... :D

 

$query=db_query("SELECT * FROM `categories` WHERE `sub`='' ORDER BY `name`");
$categories=array();
while($row=mysql_fetch_array($query)){
if(!empty($row[secure])) if(!secure($row[secure])) continue;
if($_GET[cat]==$row[id]){
  $categories[]='<a href="?op=products&cat='.$row[id].'" class=title>'.ucwords($row[name]);
  $query2=db_query("SELECT * FROM `categories` WHERE `sub`='$row[id]' ORDER BY `name`");
  while($row2=mysql_fetch_array($query2)){
   if(!empty($row2[secure])) if(!secure($row2[secure])) continue;
   if($_GET[sub]==$row2[id]) $categories[]='<a href="?op=products&cat='.$row[id].'&sub='.$row2[id].'" class=subtitle><span class=subcat>'.ucwords($row2[name]).'</span></a>';
   else $categories[]='<a href="?op=products&cat='.$row[id].'&sub='.$row2[id].'"><span class=subcat>'.ucwords($row2[name]).'</span></a>';
  }
}else $categories[]='<a href="?op=products&cat='.$row[id].'">'.ucwords($row[name]).'</a>';
}
sort($categories);
$left=implode("<br>",$categories);

Link to comment
Share on other sites

Incase this helps what i have so far

 

<?php

class tree
{
public $tree;
}
class node
{
public $nvalue;
public $nparent;
public $nchild;
}
$phpTree= new tree();

$PHP = new node();
$PHP->nvalue = "PHP";
$PHP->nchild = Array("About","Execution");
$PHP->nparent = null;

$About = new node();
$About->nvalue = "About";
$About->nchild= Array("About PHP","About PHP2");
$About->nparent = $PHP;

$aboutSub1 = new node();
$aboutSub1->nvalue = "About PHP";
$aboutSub1->nparent = $About;

$aboutSub2 = new node();
$aboutSub2->nvalue = "About PHP2";
$aboutSub2->nparent = $About;

$History = new node();
$History->nvalue = "History";
$History->nparent = $PHP;

$phpTree->tree=Array(
					$PHP,
					$About,
					$aboutSub1,
					$aboutSub2,
					$History);


//print_r($phpTree);

$searchValue = "About";
$foundValues = Array();

foreach($phpTree as $node)
{
foreach($node as $value)
{
	if($value->nvalue == $searchValue)
	{
		if($value->nchild != null)
		{
			foreach($value->nchild as $child)
			{
				array_push($foundValues,$child);
			}
		}
		array_push($foundValues,$value->nvalue);
		while($value->nparent != null)
		{
			$value = $value->nparent;
			array_push($foundValues,$value->nvalue);
		}
	}
}
}

$foundValues = array_reverse($foundValues);

echo "<table>";
foreach($foundValues as $name)
{
echo "<tr><td>$name</td><tr>";
}
echo "</table>";
?>

Link to comment
Share on other sites

<?php

class tree
{
public $tree;
}
class node
{
public $nvalue;
public $nparent;
public $nchild;
}
$phpTree= new tree();

$PHP = new node();
$PHP->nvalue = "PHP";
$PHP->nchild = Array("About","Execution");
$PHP->nparent = null;

$About = new node();
$About->nvalue = "About";
$About->nchild= Array("About PHP","About PHP2");
$About->nparent = $PHP;

$Execution = new node();
$Execution->nvalue = "Execution";
$Execution->nchild= Array("Excution PHP","Excution PHP2");
$Execution->nparent = $PHP;

$Execution1 = new node();
$Execution1->nvalue = "Execution PHP";
$Execution1->nparent = $Execution;

$Execution2 = new node();
$Execution2->nvalue = "Execution PHP2";
$Execution2->nparent = $Execution1;

$aboutSub1 = new node();
$aboutSub1->nvalue = "About PHP";
$aboutSub1->nparent = $About;

$aboutSub2 = new node();
$aboutSub2->nvalue = "About PHP2";
$aboutSub2->nparent = $About;

$History = new node();
$History->nvalue = "History";
$History->nparent = $PHP;

$phpTree->tree=Array(
					$PHP,
					$About,
					$aboutSub1,
					$aboutSub2,
					$History,
					$Execution,
					$Execution1,
					$Execution2
					);


//print_r($phpTree);

$searchValue = $_GET[myName];
$foundValues = Array();

foreach($phpTree as $node)
{
foreach($node as $value)
{
	if($value->nvalue == $searchValue)
	{
		if($value->nchild != null)
		{
			foreach($value->nchild as $child)
			{
				array_push($foundValues,$child);
			}
		}
		array_push($foundValues,$value->nvalue);
		while($value->nparent != null)
		{
			$value = $value->nparent;
			array_push($foundValues,$value->nvalue);
			foreach($value->nchild as $child)
			{
				array_push($foundValues,$child);
			}
			array_push($foundValues,$value->nvalue);
		}
	}
}
}

$foundValues= array_reverse($foundValues);
$foundValues = array_unique ($foundValues);

echo "<table>";
foreach($foundValues as $name)
{
echo "<tr><td><a href=./navigation.php?myName=".$name.">$name</a></td><tr>";
}
echo "</table>";
?>

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.