Jump to content

[SOLVED] include() question - please help!


damnsaiyan

Recommended Posts

Okay so I've made the main layout of my website called main.php. It's basically the structured page with all the menu links at the top and graphics etc. In a table inside this layout, I want to use PHP to put the contents of a file in (e.g. contact.html). How do you do that with PHP?

 

I'm able to use the include() function to put both files on the same page. But I don't know how to place the contents of contact.html in a specific part of main.php

 

I've done it before but I've forgotten now. I remember that in the address bar I would have to use something like "www.blahblah.com/main.php?=contact.html (or something vaguely like that!!).

 

Just to clarify, I only want one core file for the layout, and a number of files that only consist of the content of each page (i.e. the writing).

Link to comment
Share on other sites

But then wouldn't that result in multiple copies of the main file (layout file)?  What I want is a single main file so that if I want to change the layout of the site, I can do so by simply changing that one file. (You can tell I'm new to this lol)

 

this is not clear sorry !

Link to comment
Share on other sites

Okay, I'll try again sorry!  :)

 

 

 

Main.php -- a layout page. It has the banner, basic structure of the site, menu etc. But no actual content inside of it (i.e. no information I want to use). 

 

Contact.htm -- Just basic text. No formatting..what I want to go in the layout.

 

Links.htm -- Just basic text again.

 

 

 

 

So if I used the include() method that person stated above wouldn't I have to create a new set of files (e.g. contact.php, links.php). 

 

For example, the contact.php would be main.php+contact.htm ----> Because it would be a copy of the main file with the following code inserted: include(contact.htm');

 

Then links.php would be main.htm+links.htm etc.

 

What I'm looking for is a way to have a code in main.php that mean if I typed in the address bar something like "www.domain.com/main.php?=links.htm" ----I don't know if that's the exact way you write it. But anyway, typing that address would make links.htm appear in main.php whereever you wrote that certain code...

 

Link to comment
Share on other sites

I think that's it! I'll give that a go, thanks!

 

For the code, do I have to insert all the page names then? And the URL will filter out which one is needed right? And after the last 'case' in the code, there's no other things that need 'closing' (I'm so rubbish on the terminology!). I just put in } at the end?

Link to comment
Share on other sites

maybe this

www.domain.com/main.php?pages=links

 

switch($_GET['pages']){
   case 'link':
        include 'links.php';
        break;
   case 'contact':
        include 'contact.php';
   break;
etc....
}

 

 

I had a go with this but it didn't work... the content I want to show up didn't... :/

 

I also had a try with a code I found from that site that was suggested and that didn't work either.  Could someone explain it for me please (keeping in mind I'm a begginer) :)

Link to comment
Share on other sites

hi,

if your url is http://www.domain.com/main.php?pages=link

then

switch($_GET['pages']){

  case 'link':

        include 'links.php'; //it shud get included.

        break;

  case 'contact':

        include 'contact.php';

  break;

etc....

}

You are trying to echo the html in specific reason according to the questioned page in url??

 

what output you are expecting or what is the error?

 

Link to comment
Share on other sites

I don't understand that question: "You are trying to echo the html in specific reason according to the questioned page in url??" Sorry  :-\

 

As for the output I'm expecting- I want the contents of link.html to appear somewhere inside main.php. I get no error, the content just doesn't appear.

Link to comment
Share on other sites

I don't understand that question: "You are trying to echo the html in specific reason according to the questioned page in url??" Sorry  :-\

 

As for the output I'm expecting- I want the contents of link.html to appear somewhere inside main.php. I get no error, the content just doesn't appear.

 

oops sorry but i was just trying to ask you what your second statement say :-)

 

anywayz kindly check if that file output correctly if it run independently.

 

Regards

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.