Page 1 of 1

help! PHP includes

Posted: Fri Jun 12, 2009 2:29 am
by powerlines
Hi

I am a little new to PHP so please excuse the possable noob question.

I have a text menu,

Item 1
Item 2
Item 3

Which is called by a simple include on each of the main pages.

I then have a sub menu for the product pages.

Item 1
Item 2
Product 1
Product 2
Product 3
Item 3

Which is a seperate include when "Item 2" is clicked (this then stays perminantly)

I then have several more includes (other sub menus) for when other "Items" are clicked, which appear and dissappear when needed.

I am up to about 5-6 nav includes :cry:

My question is this.

Is there a way of having it reduced to less includes and have the sub menu appear when an "Item 2" is clicked ?
Is it then possable to have the sub menu for "Item 2" to stay regardless of where else people navigate and what other sub menus appear?

I understand this Is possably a cack handed way of asking a question but hope you get the gist.

Please ask any questions you like and thanks in advance.

Re: help! PHP includes

Posted: Fri Jun 12, 2009 4:55 am
by vtvstv
Not sure if im completely getting the gist of your question but couldnt you put the submenus inside a div aligned to your menu with CSS and then a small show/hide javascript that would change the class of the div onClick calling the show CSS class...

Re: help! PHP includes

Posted: Thu Jun 18, 2009 10:54 am
by powerlines
Hi

Sorry will try and explain better....

I have a menu:

Home
About
Online shopping
Wedding collection
Contact

This is called like this

Code: Select all

<div id="navigation">
<?php
include "nav.php";
?>
</div>
On every page.

When a user clicks on Wedding collection it brings up the page and alters the menu to this:

Home
About
Online shopping
Wedding collection
Wedding Jewellery
Contact

This is called on the Wedding Collection page like this.

Code: Select all

<div id="navigation">
<?php
include "nav_wedding.php";
?>
</div>
What i need to happen is after a user has visited this page and bought up this sub menu it needs to stay visable no matter where they navigate too.

Please help it is driving me nuts.

Re: help! PHP includes

Posted: Thu Jun 18, 2009 11:53 am
by jgadrow
If this needs to be remembered across page requests, you will need to store the data in a $_SESSION.

Re: help! PHP includes

Posted: Thu Jun 18, 2009 12:06 pm
by powerlines
Hi

Fairly new to PHP any chance you could give me a breif example as would really help.

Cheers

Re: help! PHP includes

Posted: Thu Jun 18, 2009 12:31 pm
by jgadrow
I saw that you're new. Was hoping you'd do a quick google on php sessions. But, basically, you need to do something like this:

Code: Select all

<?php
session_start ();
 
// write possible data to session
if (isset ($_GET ['menu']))
{
    $_SESSION ['activemenu'] = $_GET ['menu'];
}
 
if (isset ($_SESSION ['activemenu']))
{
    printf ('I should be displaying this submenu: %s', $_SESSION ['activemenu']);
}
?>
Save this as index.php and, in your browser visit: index.php?menu=test1
After doing so, it will say: I should be displaying this submenu: test1

Now, just visit index.php. It will STILL say: I should be displaying this submenu: test1

This is because the session is preserved across page requests. I advise you play around with it a while as there are an absolute TON of security considerations dealing with session management. But, that should get you started. :)