damnsaiyan Posted January 9, 2008 Share Posted January 9, 2008 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). Quote Link to comment https://forums.phpfreaks.com/topic/85265-solved-include-question-please-help/ Share on other sites More sharing options...
drummer101 Posted January 9, 2008 Share Posted January 9, 2008 Where you would normally write the HTML or whatever for layout, put include('path/to/your/file.php'); Quote Link to comment https://forums.phpfreaks.com/topic/85265-solved-include-question-please-help/#findComment-435009 Share on other sites More sharing options...
damnsaiyan Posted January 9, 2008 Author Share Posted January 9, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/85265-solved-include-question-please-help/#findComment-435013 Share on other sites More sharing options...
damnsaiyan Posted January 9, 2008 Author Share Posted January 9, 2008 Anyone? ??? Quote Link to comment https://forums.phpfreaks.com/topic/85265-solved-include-question-please-help/#findComment-435061 Share on other sites More sharing options...
teng84 Posted January 10, 2008 Share Posted January 10, 2008 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 ! Quote Link to comment https://forums.phpfreaks.com/topic/85265-solved-include-question-please-help/#findComment-435066 Share on other sites More sharing options...
damnsaiyan Posted January 10, 2008 Author Share Posted January 10, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/85265-solved-include-question-please-help/#findComment-435118 Share on other sites More sharing options...
teng84 Posted January 10, 2008 Share Posted January 10, 2008 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.... } Quote Link to comment https://forums.phpfreaks.com/topic/85265-solved-include-question-please-help/#findComment-435128 Share on other sites More sharing options...
damnsaiyan Posted January 10, 2008 Author Share Posted January 10, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/85265-solved-include-question-please-help/#findComment-435139 Share on other sites More sharing options...
teng84 Posted January 10, 2008 Share Posted January 10, 2008 break is the terminator of the switch statement if you want to add something just follow the structure or look for the <a href="http://www.php.net/manual/en/control-structures.switch.php"> sample </a> Quote Link to comment https://forums.phpfreaks.com/topic/85265-solved-include-question-please-help/#findComment-435146 Share on other sites More sharing options...
damnsaiyan Posted January 10, 2008 Author Share Posted January 10, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/85265-solved-include-question-please-help/#findComment-435426 Share on other sites More sharing options...
priti Posted January 10, 2008 Share Posted January 10, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/85265-solved-include-question-please-help/#findComment-435433 Share on other sites More sharing options...
damnsaiyan Posted January 10, 2008 Author Share Posted January 10, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/85265-solved-include-question-please-help/#findComment-435443 Share on other sites More sharing options...
priti Posted January 11, 2008 Share Posted January 11, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/85265-solved-include-question-please-help/#findComment-436294 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.