Sharky01276 Posted May 12, 2007 Share Posted May 12, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51053-navigation-menu/ Share on other sites More sharing options...
taith Posted May 12, 2007 Share Posted May 12, 2007 i made this a while ago... maybe ya can find it useful to look at... $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); Quote Link to comment https://forums.phpfreaks.com/topic/51053-navigation-menu/#findComment-251240 Share on other sites More sharing options...
Sharky01276 Posted May 12, 2007 Author Share Posted May 12, 2007 Yeh kinda looked at what uve got going on there. Lots of mysql tutorials but im trying to do this just on one page. Dont ask why I think the functionality is there if i pout my head to it its just so fugly Quote Link to comment https://forums.phpfreaks.com/topic/51053-navigation-menu/#findComment-251249 Share on other sites More sharing options...
Sharky01276 Posted May 12, 2007 Author Share Posted May 12, 2007 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/51053-navigation-menu/#findComment-251259 Share on other sites More sharing options...
Sharky01276 Posted May 12, 2007 Author Share Posted May 12, 2007 <?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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/51053-navigation-menu/#findComment-251266 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.