472,954 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 software developers and data experts.

Need help to code collapsing menu

Hi,

I am trying to code a menu for a webpage, the menu is broken up to groups
i.e:

Home
Group1
*menuitem1
*menuitem2
*menuitem3
Group2
**menuitem1
**menuitem2
*menuitem3
And so on.

What I want to achieve is that the groups are shown in a collapsed state
depending on the page which is currently being displayed i.e so it starts
out like this

Home
Group1
Group2

If you click on Group1 it loads the first menuitem page and highlights it
and redraws the page expanding that group i.e. (note * denotes highligthed)
Home
Group1
**menuitem1
***menuitem2
***menuitem3*
Group2

And the same would apply if you click on Group2 i.e:
Home
Group1
Group2
**menuitem1
****menuitem2
****menuitem3*

What is the best way to go about this? I have coded it 'the long way' where
there is lots of duplication of code.

I hope this all makes sense and that I have explained it clearly.

I am new to php so would really appreciate your help as I am totally at a
loss on how to best do this.

Many thanks

Rigga
Jul 17 '05 #1
11 2219
SOR
<comp.lang.php , rigga , ri***@hasnomail.com>
<42***********************@ptn-nntp-reader01.plus.net>
<Fri, 08 Jul 2005 19:12:36 +0100>
What is the best way to go about this? I have coded it 'the long way' where
there is lots of duplication of code.

I hope this all makes sense and that I have explained it clearly.

I am new to php so would really appreciate your help as I am totally at a
loss on how to best do this.


Using includes should make it quite easy - even for a newbie like me .

blah.php?pass=1 on your main group link .

Assuming you have the nav menu as a include you could do a 'if' and if
the value is 1 then display the extra sub menu links .

Although , You would need the ?pass=1 on all the sub links as well or
the sub menu would disappear when you clicked on sub link .

As a fellow php newbie i've found getting stuff working first and then
trying to tweak and fine tune it later can be useful .
Jul 17 '05 #2
SOR wrote:
<comp.lang.php , rigga , ri***@hasnomail.com>
<42***********************@ptn-nntp-reader01.plus.net>
<Fri, 08 Jul 2005 19:12:36 +0100>
What is the best way to go about this? I have coded it 'the long way'
where there is lots of duplication of code.

I hope this all makes sense and that I have explained it clearly.

I am new to php so would really appreciate your help as I am totally at a
loss on how to best do this.


Using includes should make it quite easy - even for a newbie like me .

blah.php?pass=1 on your main group link .

Assuming you have the nav menu as a include you could do a 'if' and if
the value is 1 then display the extra sub menu links .

Although , You would need the ?pass=1 on all the sub links as well or
the sub menu would disappear when you clicked on sub link .

As a fellow php newbie i've found getting stuff working first and then
trying to tweak and fine tune it later can be useful .

Could you explain further?, how would I get it to highlite the active link?

Jul 17 '05 #3
SOR
<comp.lang.php , rigga , ri***@hasnomail.com>
<42**********************@ptn-nntp-reader04.plus.net>
<Sat, 09 Jul 2005 09:11:39 +0100>
Could you explain further?, how would I get it to highlite the active link?


www.snipe.net this guys nav menu uses the sort of thing you want to do -
it might be worth a email to ask him for the source code as his method
is probably better than mine .
Jul 17 '05 #4
SOR
<comp.lang.php , SOR , we*******@sparesorrepair.co.uk.INVALID>
<MP************************@no-cancel.newsreader.com>
<Sat, 9 Jul 2005 13:30:08 +0100>
Could you explain further?, how would I get it to highlite the active link?


www.snipe.net this guys nav menu uses the sort of thing you want to do -
it might be worth a email to ask him for the source code as his method
is probably better than mine .


www.ganjahost.co.uk/rigga

www.ganjahost.co.uk/rigga/rigga.zip

Keep in mind i'm a newbie like yourself and this is probably the worse
way to do it .

Jul 17 '05 #5
I noticed that Message-ID:
<MP************************@no-cancel.newsreader.com> from SOR contained
the following:
www.ganjahost.co.uk/rigga


doesn't work in FF.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #6
SOR
<comp.lang.php , Geoff Berrow , bl******@ckdog.co.uk>
<is********************************@4ax.com>
<Sat, 09 Jul 2005 15:30:54 +0100>
www.ganjahost.co.uk/rigga


doesn't work in FF.


Then try it at normal speed :-))
Jul 17 '05 #7
On Sat, 09 Jul 2005 15:32:33 +0100, SOR wrote:
<comp.lang.php , Geoff Berrow , bl******@ckdog.co.uk>
<is********************************@4ax.com>
<Sat, 09 Jul 2005 15:30:54 +0100>
>www.ganjahost.co.uk/rigga


doesn't work in FF.


Then try it at normal speed :-))

Thank you thats exactly what I was trying to achieve, I will look over the
code and see if I understand it. Like Geoff said it doesn't work in
Firefox though, but I will look in to that.

I really appreciate you taking the time to help me with this.

all the best

Jul 17 '05 #8
SOR
<comp.lang.php , rigga , ri***@hasnomail.com>
<pa****************************@hasnomail.com>
<Sat, 09 Jul 2005 21:31:34 +0100>
Like Geoff said it doesn't work in
Firefox though, but I will look in to that.


Putting a <br> at the end of the <a> tags would probably sort it .

Fartfox often screws things up :-)
Jul 17 '05 #9
SOR
<comp.lang.php , SOR , we*******@sparesorrepair.co.uk.INVALID>
<MP************************@no-cancel.newsreader.com>
<Sun, 10 Jul 2005 01:06:53 +0100>
Putting a <br> at the end of the <a> tags would probably sort it .


Either way the following is probably a better way of doing it as it does
away with 2 include files .
inc_nav.php

<?php $rigga = $_GET['pass']; ?>

<a href="index.php" class="butnav">HOME</a><br>
<a href="group_one.php?pass=1" class="butnav">GROUP ONE</a><br>
<?php if ($rigga==1) {g_one();} ?>
<a href="group_two.php?pass=2" class="butnav">GROUP TWO</a><br>
<?php if ($rigga==2) {g_two();} ?>
<a href="index.php" class="butnav">HOME</a><br>

<?php
function g_one()
{
print "<a href=index.php?pass=1 class=butnav>..... GROUP ONE</a><br>";
print "<a href=index.php?pass=1 class=butnav>..... GROUP ONE</a><br>";
}
?>

<?php
function g_two()
{
print "<a href=index.php?pass=2 class=butnav>..... GROUP TWO</a><br>";
print "<a href=index.php?pass=2 class=butnav>..... GROUP TWO</a><br>";
}
?>
Jul 17 '05 #10
SOR
<comp.lang.php , SOR , we*******@sparesorrepair.co.uk.INVALID>
<MP************************@no-cancel.newsreader.com>
<Sun, 10 Jul 2005 16:08:21 +0100>
inc_nav.php


Being a newbie I was curious how to do it without using stuff like
?pass=1 in the url and came up with this .

Do a cut-n-paste into inc_nav.php

<?php $filename=$_SERVER["REQUEST_URI"]; ?>

<a href="index.php" class="butnav">HOME</a><br>
<a href="group_one.php" class="butnav">GROUP ONE</a><br>
<?php if ($filename=="/rigged/group_one.php") {g_one();} ?>
<a href="group_two.php" class="butnav">GROUP TWO</a><br>
<?php if ($filename=="/rigged/group_two.php") {g_two();} ?>
<a href="index.php" class="butnav">HOME</a><br>

<?php
function g_one()
{
print "<a href=index.php class=butnav>..... GROUP ONE</a><br>";
print "<a href=index.php class=butnav>..... GROUP ONE</a><br>";
}
?>

<?php
function g_two()
{
print "<a href=index.php class=butnav>..... GROUP TWO</a><br>";
print "<a href=index.php class=butnav>..... GROUP TWO</a><br>";
}
?>


<?php if ($filename=="/rigged/group_one.php") {g_one();} ?>

"/rigged/group_one.php"

/rigged/ being the folder name i used and you will need to adjust this
to suit your own webspace .
Jul 17 '05 #11
SOR
<comp.lang.php , SOR , we*******@sparesorrepair.co.uk.INVALID>
<MP************************@no-cancel.newsreader.com>
<Sun, 10 Jul 2005 19:51:41 +0100>
Being a newbie I was curious how to do it without using stuff like
?pass=1 in the url and came up with this .

Do a cut-n-paste into inc_nav.php

<?php $filename=$_SERVER["REQUEST_URI"]; ?>

<a href="index.php" class="butnav">HOME</a><br>
<a href="group_one.php" class="butnav">GROUP ONE</a><br>
<?php if ($filename=="/rigged/group_one.php") {g_one();} ?>
<a href="group_two.php" class="butnav">GROUP TWO</a><br>
<?php if ($filename=="/rigged/group_two.php") {g_two();} ?>
<a href="index.php" class="butnav">HOME</a><br>


And perhaps a good reason why you shouldnt listen to a newbie .

If you clicked on a sub menu link - the sub menu would disappear .

This seems to work quite well though , Thanks for asking the question
dude as I learnt loads from doing it .


inc_nav.php

<?php $filename=$_SERVER["REQUEST_URI"]; ?>

<?php $g1=0; $g2=0; ?>

<?php

if ($filename=="/rigged/group_one.php") {$g1=1;}
if ($filename=="/rigged/anythings.php") {$g1=1;}
if ($filename=="/rigged/bigjobbys.php") {$g1=1;}

if ($filename=="/rigged/group_two.php") {$g2=1;}
if ($filename=="/rigged/blahblahs.php") {$g2=1;}
if ($filename=="/rigged/foofoofoo.php") {$g2=1;}

?>

<a href="index.php" class="butnav">HOME</a><br>
<a href="group_one.php" class="butnav">GROUP ONE</a><br>
<?php if ($g1==1) {g_one();} ?>
<a href="group_two.php" class="butnav">GROUP TWO</a><br>
<?php if ($g2==1) {g_two();} ?>
<a href="index.php" class="butnav">HOME</a><br>

<?php
function g_one()
{
print "<a href=index.php class=butnav>..... GROUP ONE</a><br>";
print "<a href=index.php class=butnav>..... GROUP ONE</a><br>";
}
?>

<?php
function g_two()
{
print "<a href=index.php class=butnav>..... GROUP TWO</a><br>";
print "<a href=index.php class=butnav>..... GROUP TWO</a><br>";
}
?>

Jul 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jeremy Epstein | last post by:
Hi guys, I've got a page that shows a number of packages available for sale. Each package has a little description, and then a (sometimes long) list of features for each package. I thought it...
5
by: Borris | last post by:
<div style="background-color: blue; width: 500px; height: 300px"> <div style="background-color: red; margin-top: 100px; margin-left: 100px; width: 300px; height: 100px"> </div> </div> Where...
2
by: Stanimir Stamenkov | last post by:
I'm trying to clear some sizing issues relative to the initial containing block and the root document element. The sample document I'm trying with: http://stanio.info/viewport_fill.html ...
1
by: yb | last post by:
Hi, I'm looking for clarification of css 2.1 specification in section 8.3.1 "Collapsing Margins" The 6th bullet reads "If the top and bottom margins of a box are adjoining ..." I won't paste...
6
by: Jack | last post by:
Hello, I would like some advice on how to disable the behavior of treeviews to expand and collapse when double clicked upon, but still allow the user to use the plus and minus on each node. ...
4
by: Andreas Prilop | last post by:
How many spaces should be displayed in A <span style="display:none">x</span> B between "A" and "B"? I notice that Mozilla displays one space and Internet Explorer (5 & 6) displays two spaces....
0
by: Jack | last post by:
Hello, I am looking to denormalize XML into a few tables, does anyone know of open source software that I can use to map the collapsing and then generate the SQL ? I know xmlspy does this but...
5
by: SlowArrow | last post by:
Here collapsing seems to work differently in vb.net 2005 from that I use to see in vb.net 2003: Using the collapsing in vb.net 2003 shows the whole interface of the methods, subroutines,...
9
by: Academia | last post by:
ContextMenu has a Popup event but MainMenu does not. I need Popup with MainMenu. Do you know anyway to simulate it? Thanks in advance
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.