help! PHP includes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
powerlines
Forum Newbie
Posts: 3
Joined: Fri Jun 12, 2009 2:13 am

help! PHP includes

Post 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.
vtvstv
Forum Newbie
Posts: 10
Joined: Sun May 24, 2009 3:19 am

Re: help! PHP includes

Post 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...
powerlines
Forum Newbie
Posts: 3
Joined: Fri Jun 12, 2009 2:13 am

Re: help! PHP includes

Post 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.
User avatar
jgadrow
Forum Newbie
Posts: 22
Joined: Wed Jun 17, 2009 7:56 pm
Location: Cincinnati, Ohio
Contact:

Re: help! PHP includes

Post by jgadrow »

If this needs to be remembered across page requests, you will need to store the data in a $_SESSION.
powerlines
Forum Newbie
Posts: 3
Joined: Fri Jun 12, 2009 2:13 am

Re: help! PHP includes

Post by powerlines »

Hi

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

Cheers
User avatar
jgadrow
Forum Newbie
Posts: 22
Joined: Wed Jun 17, 2009 7:56 pm
Location: Cincinnati, Ohio
Contact:

Re: help! PHP includes

Post 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. :)
Post Reply