[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 09-11-2005, 04:55 AM   #1 (permalink)
New Member
 
Join Date: Mar 2005
Posts: 9
18.00 NP$ (Donate)

j0n87 is an unknown quantity at this point


Include files

Hi

I have a website made in html.
I got like 20 different pages in the site, and i have just copied the index.html 20 times and changed the content in every page.
When i want to change something in the Menu, i have to edit all 20 files, and that take too much time.

Now i got a php host, and want to use the Include php thing.
I want like the Header and Menu as index.php, and use <?php include("index2.php") ?> in the content.



I've searched around in google, but didnt find enough info about this,
so i hope you guys can help me.

Thanks
j0n87 is offline  
Old 09-11-2005, 05:04 AM   #2 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


include("filename.php"); means just include the code from that file
include once("filename.php"); means include the code from that file but no more than once.
require("filename.php"); means include the code from that file but if there's an error, don't open the rest of the code.


Something like that anyway. Sorry, I'm half asleep


__________________________________________________

Further more...

I remember when I first started using includes and I didn't realize it included the code rather than the design in Dreamweaver (I was stupid ). But code the 'index.php' first of all, then take portions of it (the header and the menu will probably be a good idea if the menu is on the left) and save it as "head.php". Then in the index.php, use ..

PHP Code:
include ("head.php");
Repeat for the footer of the page.

Last edited by miseria; 09-11-2005 at 05:07 AM.
miseria is offline  
Old 09-11-2005, 07:32 AM   #3 (permalink)
NamePros Regular
 
NuPagady's Avatar
 
Join Date: Jul 2005
Location: Lithuania
Posts: 474
42.43 NP$ (Donate)

NuPagady is on a distinguished road


Also, you have mentioned that you have 20 pages, so you can use something like that:
Code:
<?

switch ($_GET["page"]) {
case 1:
   include("index1.html");
case 2:
   include("index2.html");
case 3:
   include("index3.html");
case 4:
   include("index4.html");
}

?>
so if you will go to yourwebsite.com/index.php?page=1 it will open index1.html, if you will go to yourwebsite.com/index.php?page=2 it will open index2.html, etc..

But first of all, make header and footer, as miseria mentioned.
NuPagady is offline  
Old 09-27-2005, 02:03 PM   #4 (permalink)
New Member
 
Join Date: Mar 2005
Posts: 9
18.00 NP$ (Donate)

j0n87 is an unknown quantity at this point


i got what u said miseria, but not what NuPagady said.
can you explain better, or someone else?
with the whole code?

this is what i tried, but didnt success:
PHP Code:
<?php include("head.php"); ?>

<?

include_once("content.php");

switch (
$_GET["page"]) {
case
1:
   include(
"content.php");
case
2:
   include(
"downloads.php");
}

?>

<?php include("foot.php"); ?>
j0n87 is offline  
Old 09-27-2005, 02:48 PM   #5 (permalink)
Senior Member
 
legend2's Avatar
 
Join Date: Sep 2005
Posts: 1,102
141.05 NP$ (Donate)

legend2 has much to be proud oflegend2 has much to be proud oflegend2 has much to be proud oflegend2 has much to be proud oflegend2 has much to be proud oflegend2 has much to be proud oflegend2 has much to be proud oflegend2 has much to be proud oflegend2 has much to be proud of


add a break; after each include in the case
legend2 is offline  
Old 09-27-2005, 02:53 PM   #6 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Meh...

PHP Code:

/*You'll need links to the releveant pages. I.E. :
<a href='index.php?page=2'>Downloads</a> Would include the downloads.php content, etc.*/

<?php

include("head.php");
include_once(
"content.php");

switch (
$_GET["page"])
{
case
1:
   include(
"content.php");
   break;
case
2:
   include(
"downloads.php");
   break;
}

include(
"foot.php");

?>
__________________

Last edited by SecondVersion; 09-27-2005 at 07:11 PM.
Eric is offline  
Old 09-27-2005, 03:47 PM   #7 (permalink)
New Member
 
Join Date: Mar 2005
Posts: 9
18.00 NP$ (Donate)

j0n87 is an unknown quantity at this point


the break; thing didnt do anything difference.
when i change site, the last include file is still there.

is this how a index.php is builded?
j0n87 is offline  
Old 09-27-2005, 04:41 PM   #8 (permalink)
Account Closed
 
Join Date: Jul 2005
Posts: 102
42.10 NP$ (Donate)

Archimed will become famous soon enoughArchimed will become famous soon enough


kind of, i am budling like that... www.ipgfx.net/test/index1.php
Archimed is offline  
Old 09-28-2005, 03:30 AM   #9 (permalink)
NamePros Regular
 
NuPagady's Avatar
 
Join Date: Jul 2005
Location: Lithuania
Posts: 474
42.43 NP$ (Donate)

NuPagady is on a distinguished road


Quote:
Originally Posted by j0n87
i got what u said miseria, but not what NuPagady said.
can you explain better, or someone else?
with the whole code?

this is what i tried, but didnt success:
PHP Code:
<?php include("head.php"); ?>

<?

include_once("content.php");

switch (
$_GET["page"]) {
case
1:
   include(
"content.php");
case
2:
   include(
"downloads.php");
}

?>

<?php include("foot.php"); ?>

Ok, I made an example for you. First of all, visit the link below to see how it works:
http://www.nupagady.info/j0n87/

There are 6 files in the folder: index.php, head.php, foot.php, content.php, downloads.php and empty.php

index.php:
Code:
<?

include("head.php"); // 1. script will include header

switch ($_GET["page"]) { // script will check variable "page" from the link
case 1: // If the link is index.php?page=1, it will include "content.php"
   include("content.php");
   break;
case 2: // If the link is index.php?page=2, it will include "download.php"
   include("downloads.php");
   break;
default: // If variable "page" is not specified, script will include "empty.php"
   include ("empty.php");
}

include("foot.php"); // script will include footer

?>
head.php:
Code:
This is header <br>
-------------------------------------------------
<br>
foot.php:
Code:
<br>
-------------------------------------------------
<br>
This is footer
content.php:
Code:
"content.php" file.<br>
If you'd like to include "downloads.php", <a href="index.php?page=2">click here</a>.
downloads.php:
Code:
"downloads.php" file.<br>
If you'd like to include "content.php", <a href="index.php?page=1">click here</a>.
empty.php:
Code:
If you'd like to include "content.php", <a href="index.php?page=1">click here</a>;<br>
If you'd like to include "downloads.php", <a href="index.php?page=2">click here</a>.
I have also attached the archive with all files. Download if you need it.


P.S. sorry for my broken english
Attached Files
File Type: zip include.zip (1.3 KB, 3 views)
NuPagady is offline  
Old 09-28-2005, 04:16 AM   #10 (permalink)
New Member
 
Join Date: Mar 2005
Posts: 9
18.00 NP$ (Donate)

j0n87 is an unknown quantity at this point


NuPagady, thank you very much for this.
Now it all works.
And there is nothing wrong with your english

Edit**
Is it possible to change the numbers with words?
Like this: index.php?page=downloads

Last edited by j0n87; 09-28-2005 at 04:29 AM.
j0n87 is offline  
Old 09-28-2005, 04:54 AM   #11 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Quote:
Originally Posted by j0n87
NuPagady, thank you very much for this.
Now it all works.
And there is nothing wrong with your english

Edit**
Is it possible to change the numbers with words?
Like this: index.php?page=downloads
Yes:

PHP Code:
<?

include("head.php"); // 1. script will include header

switch ($_GET["page"]) { // script will check variable "page" from the link
case content: // If the link is index.php?page=content, it will include "content.php"
   
include("content.php");
   break;
case
downloads: // If the link is index.php?page=downloads, it will include "download.php"
   
include("downloads.php");
   break;
default:
// If variable "page" is not specified, script will include "empty.php"
   
include ("empty.php");
}

include(
"foot.php"); // script will include footer

?>
__________________
Eric is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Totorial - Adding Music to your Site abacomedia Webmaster Tutorials 7 08-27-2005 08:12 AM
Centering PHP included files FreeBaGeL Programming 1 07-16-2005 11:01 AM
Using Music on your Site - WAV, MP3, MIDI, Flash? abacomedia Web Design Discussion 1 05-20-2004 01:04 PM
Include external files with out the use of server side technology deadserious CODE 2 12-08-2002 10:43 AM

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 04:32 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85