473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Collapsing Menu - please help

Hi,

I am relatively new to php and am currently working on a site where I need
to use a collapsing menu system. I have written the code to do this
however I am completely at a loss to do one particular thing. To best
explain what the problem is I will give you an overview of how the menu
hangs together.

The menu looks like this:

Catagory1 (note these look like buttons)
Catagory2
Catagory3

When a user clicks on a catagory that catagory expands to show the sub
catagories and the menu then looks like this ( assuming they clicked on
catagory1)

Catagory1
subitem1
subitem2
Catagory2
Catagory3

If you were to click on catagory2 then the sub items for that catagory would
appear and the sub items for catagory 1 would disappear.

The menu script I created draws the catagories to look like buttons and
gives them a url in the form of 'index.php?s=#' so for example catagory1
has the url of 'index.php?s=1'

The script draws the first 'button' (catagory1)and proceeds to check to see
if that catagory is active and if so it then populates the subitems and
then loops and draws the next button (catagory2). What I would like to do
is some how when a user click on catagory1 to have the script recognise
this and rather than give the button the url of 'index.php?s=1' when the
page is drawn to simply change it to a text lable, if the user was then to
click on button 2 (catagory2) it then needs to change button 2 url to just
a text lable and button 1 url back to 'index.php?s=1'.

I hope this makes sense, i have included a cut down version of my menu
script which hopefully will make things clearer.

Any help on this will be appreciated.
---------------------------------------------------------------------------------------------
<?php
session_start();
if ((isset($_SESSION['group'])) && (!isset($_GET['s']))) {
$s = $_SESSION['group'];
}
else {
$s = $_GET[s];
}

//Get current page
$page = $_SERVER['REQUEST_URI'];
// array holds menu button names and passes menu group value
$headers = array('Cars' => 'index.php?s=1','Bikes' => 'index.php?s=2');

$sub_1 = array(
'Sports' => 'sports.php',
'Family' => 'family.php',
'4x4' => 'fourby.php'
);

$sub_2 = array(
'Motocross' => 'moto.php',
'Road' => 'road.php',
'Scooters' => 'scooter.php',
);

// Draw the menu
foreach ( $headers as $key => $value ) {

// Line below draws a button this is the part i want to be able to change
the value of if that submenu is currently active
echo "<div id=\"button\"><a href='$value'>$key</a></div>";

$_SESSION['group'] = $s;
if (($key == "Cars") && ($s == "1")) {
foreach ( $sub_1 as $key => $value ) {
$_SESSION['group'] = $s;
// Check to see if page is active is so bold it
if ($value == $page) {
echo "<b><a href='$value'>$key</a></b>";
}
else {
echo "<a href='$value'>$key</a>";
}
}

}

if (($key == "Bikes") && ($s == "2")) {
$_SESSION['group'] = $s;
foreach ( $sub_2 as $key => $value ) {
$_SESSION['group'] = $s;
// Check to see if page is active is so bold it
if ($value == $page) {
echo "<b><a href='$value'>$key</a></b>";
}
else {
echo "<a href='$value'>$key</a>";
}
}
}
}
?>
--------------------------------------------------------------------------------------------

Please note I call this script as an include from my template

Many thanks
Sep 16 '05 #1
4 1641
rigga wrote:
Hi,

I am relatively new to php and am currently working on a site where I need
to use a collapsing menu system. I have written the code to do this
however I am completely at a loss to do one particular thing. To best
explain what the problem is I will give you an overview of how the menu
hangs together.

The menu looks like this:

Catagory1 (note these look like buttons)
Catagory2
Catagory3

When a user clicks on a catagory that catagory expands to show the sub
catagories and the menu then looks like this ( assuming they clicked on
catagory1)

Catagory1
subitem1
subitem2
Catagory2
Catagory3

If you were to click on catagory2 then the sub items for that catagory
would appear and the sub items for catagory 1 would disappear.

The menu script I created draws the catagories to look like buttons and
gives them a url in the form of 'index.php?s=#' so for example catagory1
has the url of 'index.php?s=1'

The script draws the first 'button' (catagory1)and proceeds to check to
see if that catagory is active and if so it then populates the subitems
and then loops and draws the next button (catagory2). What I would like to
do is some how when a user click on catagory1 to have the script recognise
this and rather than give the button the url of 'index.php?s=1' when the
page is drawn to simply change it to a text lable, if the user was then to
click on button 2 (catagory2) it then needs to change button 2 url to just
a text lable and button 1 url back to 'index.php?s=1'.

I hope this makes sense, i have included a cut down version of my menu
script which hopefully will make things clearer.

Any help on this will be appreciated.
--------------------------------------------------------------------------------------------- <?php
session_start();
if ((isset($_SESSION['group'])) && (!isset($_GET['s']))) {
$s = $_SESSION['group'];
}
else {
$s = $_GET[s];
}

//Get current page
$page = $_SERVER['REQUEST_URI'];
// array holds menu button names and passes menu group value
$headers = array('Cars' => 'index.php?s=1','Bikes' => 'index.php?s=2');

$sub_1 = array(
'Sports' => 'sports.php',
'Family' => 'family.php',
'4x4' => 'fourby.php'
);

$sub_2 = array(
'Motocross' => 'moto.php',
'Road' => 'road.php',
'Scooters' => 'scooter.php',
);

// Draw the menu
foreach ( $headers as $key => $value ) {

// Line below draws a button this is the part i want to be able to change
the value of if that submenu is currently active
echo "<div id=\"button\"><a href='$value'>$key</a></div>";

$_SESSION['group'] = $s;
if (($key == "Cars") && ($s == "1")) {
foreach ( $sub_1 as $key => $value ) {
$_SESSION['group'] = $s;
// Check to see if page is active is so bold it
if ($value == $page) {
echo "<b><a href='$value'>$key</a></b>";
}
else {
echo "<a href='$value'>$key</a>";
}
}

}

if (($key == "Bikes") && ($s == "2")) {
$_SESSION['group'] = $s;
foreach ( $sub_2 as $key => $value ) {
$_SESSION['group'] = $s;
// Check to see if page is active is so bold it
if ($value == $page) {
echo "<b><a href='$value'>$key</a></b>";
}
else {
echo "<a href='$value'>$key</a>";
}
}
}
}
?>
--------------------------------------------------------------------------------------------
Please note I call this script as an include from my template

Many thanks

Nobody can help? or have I not explained this well enough?
Sep 17 '05 #2
rigga (ri***@hasnomail.com) wrote:

: Nobody can help? or have I not explained this well enough?

You explained it fine, but the problem involves a lot of code and is not
an interesting tricky problem, just a long one to explain, with a straight
forward answer if you just work through it yourself.

Basically, you need to figure out which "echo" command is creating the
link that needs changing. Then you need to put an if/the/else around that
echo so it either outputs a link or a label, depending on what you want
for that menu thing. Then you have to figure out what variable or set of
variables contains the information that lets you decide whether it's a
link or a label.
# you receive input,
# and then your menu loop sets a loop variable
loop on menu things
{
if ($this_loop_entry is the "same" as the $expanded_menu_item)
{
echo "the html to make a label"
}
else
{
echo "the html to make a link"
}

} # end of loop

the exact details just require some elbow grease.

--

This programmer available for rent.
Sep 17 '05 #3

rigga (ri***@hasnomail.com) wrote:

: Nobody can help? or have I not explained this well enough?


Your problem is that the PHP is not generating HTML that behaves as you
want. So, hand-code a static HTML file that *does* behave correctly,
and then compare what the PHP is generating with what it *should* be
generating.

Sep 18 '05 #4
Cats wrote:

rigga (ri***@hasnomail.com) wrote:

: Nobody can help? or have I not explained this well enough?


Your problem is that the PHP is not generating HTML that behaves as you
want. So, hand-code a static HTML file that *does* behave correctly,
and then compare what the PHP is generating with what it *should* be
generating.

Thanks for the heads up guys, I will break the code down and see where I can
fix my issue.
Sep 18 '05 #5

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

Similar topics

11
by: rigga | last post by:
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
0
by: Spartanicus | last post by:
I've been caught out by what I thought was an Opera 7.5p1 issue: http://www.spartanicus.utvinternet.ie/test/opera7.5p1_css_background_image_issue.htm but as was pointed out to me this is actually...
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...
1
by: Bhiksha Raj | last post by:
Hi, I created an expanding menu on one of the frames in my webpage using code I got from http://www.dynamicdrive.com/dynamicindex1/navigate1.htm I have embedded the code (with minor...
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...
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,...
13
Chrisjc
by: Chrisjc | last post by:
I am in need of an expanding and collapsing code… The goal is To be able to click a PICTURE IMAGE and expand to show information Reason for this is I have 3 TABLES of information of about ...
1
by: Rahsaan Page | last post by:
Hello Everybody, I am trying to write a file Explorer program in Java, i go the Frame, Basic Menu and Tree going. But now i have the C: listed and i need some help expanding and collaping the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.