Page 1 of 2

'Dynamic' PHP Navigation

Posted: Tue Apr 05, 2005 6:07 pm
by ra
I have a navigation script that displays links, and when said links are clicked on, additional navigation options appear below the original links (and can take the user to another page at the same time). I am wondering if there is a way to have each set of additional links appear under the parent link? Also, how should I code the links to return to the appropriate page regardless of location in the site?

Code: Select all

<!--menu-->
<?
// Top main menu 
echo"<a href=\"http://homepage.com/index.php">Home</a> | ";
echo"<br /><a href=\"?sort=Service\">Service</a> | <br /><a href=\"?sort=search\">Search Engine</a> | <br /><a href=\"?sort=members\">Members</a>";

function index()
{
}
$choice=$_GET['sort'];

switch($choice)
{

// EX: Service submenu
case "Service":
echo "<br /><a href=\"http://scriptsinclude.com/En/\">Many usuful scripts at ScriptsInclude.com</a>";
break;// End Service submenu

//EX: search engine submenu
case "search":
echo "<br /><a href=\"http://google.com\">Google</a> | <a href=\"http://google.com/ads/\">Google Ads Sense</a><br /><a href=\"http://yahoo.com\">Yahoo!</a><br /><a href=\"http://msn.com\">Msn</a>";
break;// End search engine submenu

//EX: search engine submenu
case "members":
echo "<br /><a href=\"http://.com\">Logged in</a><br /><a href=\"http://.com/ads/\">Lost Password</a><br /><a href=\"http://.com\">Register!</a><br /><a href=\"http://.com\">Contact Us</a>";
break;// End search engine submenu

default:
index();
}

?>
</center>
<!--End menu-->

Posted: Wed Apr 06, 2005 9:08 am
by ra
Anyone?

Posted: Wed Apr 06, 2005 9:39 am
by n00b Saibot
This can be accomplished by using JS. PHP isn't in any way 'dynamic'.

Posted: Wed Apr 06, 2005 3:42 pm
by ra
i understand that php in not dynamic, but it seems as though this can be done. The current script works fine, i just need to place the sub-menu below its parent...

Posted: Wed Apr 06, 2005 4:01 pm
by feyd
it'll require a page refresh, but it can be done... just have to output the submenu contextually from within your standard html output.

Posted: Wed Apr 06, 2005 4:29 pm
by ra
that model would work, as the parent link has a page associated with it.

button1 - folder/index.php
sub1 - folder/subpage1.php
sub2 - folder/subpage2.php
sub3 - folder/subpage3.php

What is my code missing to accomplish this?

Thanks.

...

Posted: Wed Apr 06, 2005 5:13 pm
by Calimero
Realy don't understand why do it in php, JS is made for this.

And althouh I read your post 3 times, I havent understood what are you trying to accomplish:

It look's like a simple navigation menu - and when you refresh a page you just ( as you did ) Switch and echo the nececary links - in the table if it helps to make design better .

If this is not what you want - please write to my stupid brain what are you trying to do - it looks too simple ( to code something special for it )

Posted: Wed Apr 06, 2005 5:16 pm
by Burrito
understand what you're trying to do I do not. Trying to create a "dynamic" menu are you (like a JS menu)?

Posted: Wed Apr 06, 2005 9:29 pm
by neophyte
menus like this

Posted: Thu Apr 07, 2005 3:26 am
by Burrito
There are several ways to acheive this. I'd do it in one of two ways:

1) use a url param to identify which set of subs need to be shown (use it for all subs)
2) define a constant or variable on all of your subs and show the sub menu if the constant/variable is defined/set (my preferred method)

examples:

Code: Select all

&lt;style&gt;
td.subs
{
padding-left:4px; background-color:#somediffhexcolor;
}
&lt;/style&gt;
&lt;table width=&quote;100&quote;&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quote;menuitem1.php?m1=1&quote;&gt;Menu Item 1&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quote;menuitem2.php?m2=1&quote;&gt;Menu Item 2&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?if(isset($_GET&#1111;'m2'])){?&gt;
&lt;tr&gt;
&lt;td class=&quote;subs&quote;&gt;&lt;a href=&quote;sub2a.php?m2=1&quote;&gt;Sub Menu Item 2a&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=&quote;subs&quote;&gt;&lt;a href=&quote;sub2b.php?m2=1&quote;&gt;Sub Menu Item 2b&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?} // end if for sub 2s ?&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quote;menuitem3.php?m3=1&quote;&gt;Menu Item 3&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
now the way that I'd prefer to do it:

Code: Select all

&lt;?
//define a constant for subs menu two (include this at the top of all of your sub2 pages)
define(&quote;SUBS2&quote;,1);
?&gt;
&lt;style&gt;
td.subs
{
padding-left:4px; background-color:#somediffhexcolor;
}
&lt;/style&gt;
&lt;table width=&quote;100&quote;&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quote;menuitem1.php&quote;&gt;Menu Item 1&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quote;menuitem2.php&quote;&gt;Menu Item 2&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?if(defined(&quote;SUBS2&quote;)){?&gt;
&lt;tr&gt;
&lt;td class=&quote;subs&quote;&gt;&lt;a href=&quote;sub2a.php&quote;&gt;Sub Menu Item 2a&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=&quote;subs&quote;&gt;&lt;a href=&quote;sub2b.php&quote;&gt;Sub Menu Item 2b&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?} // end if for sub 2s ?&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quote;menuitem3.php&quote;&gt;Menu Item 3&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

Posted: Fri Apr 08, 2005 3:02 pm
by ra
good talk; thanks everybody.

Dynamic PHP Navigation

Posted: Sat Apr 09, 2005 8:09 am
by marike
I personally don't see a need for PHP or Javascript for this menu. Why not just use CSS and the hover element. This way the menu looks the same even if Javascript is disable in users browser. As far as using Javascript for this, seems like a lot of code for something thats done with one line in CSS.

Unless you want to code it in PHP just 'cause you can?

Posted: Sat Apr 09, 2005 12:55 pm
by Ambush Commander
Well, IE is fussy about hover (only lets it be used on A elements).

Posted: Sat Apr 09, 2005 3:00 pm
by marike
Ambush Commander wrote:
"Well, IE is fussy about hover (only lets it be used on A elements)"

I'm not sure that's true, but...

Since it's a navigation menu, with links, which means <a href="blah">Link</a>,
isn't that what we're dealing with? A elements? And aren't there thousands of navigation menus that use CSS that work perfectly on IE?

I used alot of PHP to create this web site http://www.michaelarike.com from the gallery pages, database, email form. But for the menu I used CSS. You can make flashier menus with DHTML, but they won't be a accessible accross browsers.

I feel it's comes down to using the right tools for the task at hand.

Posted: Sat Apr 09, 2005 3:04 pm
by Chris Corbyn
Well I have a good reason for using Javascript for rollovers.

I download and stroee the images in memory when the <HEAD> loads. this means they respond instantly onMouseover instead of pausing while the new image downloads :P