Jump to content

Include() inside another include()


stifaaan

Recommended Posts

Hi Guys.. Merry Christmas

 

Im kinda new to this fantastic world of PHP and i have a little problem i hope you can help me with.

 

Im trying to build a website where I use include() to genereate my content. On my index.php i have a menu which includes

content in a content div from external .php pages, my structure kinda goes like this.. (simplified)

 

site/

  index.php

  content/

      fronpage.php

      products.php

      contact.php

 

The HTML looks like this.

 

<div id="menu">

    <ul>

          <li><a href="index.php?page=frontpage">frontpage</a></li>

          <li><a href="index.php?page=products">frontpage</a></li>

          <li><a href="index.php?page=contact">frontpage</a></li>

    </ul>         

</div               

 

<div id="main">

 

<?php

    include('/content/'.$_GET['page'].'.php');

?>

 

</div>

 

This all works very fine, but my problem is, can I have a include inside an already included page?

I would like to have a menu on my products.php site, but that page is already included from above,

and i would like the menu on the products.php site to stay as the content from the nested include

changes with input from the /products folder.

 

my idea was something like this.

 

site/

  index.php

  content/

      frontpage.php

      products.php

      contact.php

      products/

        product1.php

        product2.php

 

 

the HTML on the index.php is the same as above and then i would add the include() on the

products.php page, so its kinda the same thing, but one inside the other.

 

HTML inside the products.php folder

 

<div id="sub_menu">

    <ul>

          <li><a href="#">frontpage</a></li>

          <li><a href="#">frontpage</a></li>

          <li><a href="#">frontpage</a></li>

    </ul>         

</div               

 

<div id="sub_main">

 

<?php

    include('/content/products'.$_GET['#'].'.php');

?>

 

</div>

 

I dont know how to link to the new files so they will be included while the first include still stays on the page.

 

Any of you know how and if this can be done? Or maybe at better way to do it?

 

Hope this made sense, my first PHP question :)

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.