PHP Question please

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

RavenMist
Forum Newbie
Posts: 3
Joined: Mon Mar 29, 2004 5:41 pm

PHP Question please

Post by RavenMist »

I am making awebsite, but i want it to be friendly with every one so no iframes
BUT!! i don;'t want to make a thousand pages with the same stuff and having to update all of them if i just need to do one little link...so whats the PHP of doing it so you only change the main body of text

thanks!!
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

so whats the PHP of doing it so you only change the main body of text
I,
1) Did not understand that question, and
2) Did not understand a word you said in your above post, so
You should,
1) Re-ask your question, in regular english, and
2) Slow down when your making a post, and re-read it before you actually post it. Make sure that people can understand exactly what your talking about.
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

You need case/switch and GET variables:

Code: Select all

<form action="" method="get">
	Go to Page: <input type="text" name="page">
</form>
And on whatever page you choose to have the action be...

Code: Select all

if(isset($_GET['page']){
	$page = $_GET['page'];
	switch($page){
		case 'home':
			echo 'This is the home page.';
			break;
		case 'other':
			echo 'this is another page..';
			break;
		}
}

?>
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

i suggest using includes and just include the data that is changing

http://us3.php.net/manual/en/function.include.php

also learn about $_GET[]

then you can do something like this
example of url. http://www.mypage.com/?page=news would include news.php
http://www.mypage.com/?page=news would inlclude staff.php


Code: Select all

switch($_GET['page'])
{
   default:
   case 'news':
      include('news.php');
   break;
   case 'staff':
    include('staff.php');
    break;
}
RavenMist
Forum Newbie
Posts: 3
Joined: Mon Mar 29, 2004 5:41 pm

Post by RavenMist »

hehehe

woops :oops:

thanks every one...sorry about that.. i am not that best at english since i am a 13 year old
Last edited by RavenMist on Mon Mar 29, 2004 5:51 pm, edited 1 time in total.
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

oops Steveo31 we posted at the same time :)
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

PrObLeM wrote:oops Steveo31 we posted at the same time :)
Hehe... yea. I think I was a split second before you :P
Illusionist wrote:
so whats the PHP of doing it so you only change the main body of text
I,
1) Did not understand that question, and
2) Did not understand a word you said in your above post, so
You should,
1) Re-ask your question, in regular english, and
2) Slow down when your making a post, and re-read it before you actually post it. Make sure that people can understand exactly what your talking about.
We seemed to understand, be nice.
Last edited by Steveo31 on Mon Mar 29, 2004 5:52 pm, edited 1 time in total.
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

oh i forgot to mention the linkes would look like this

Code: Select all

<a href="?page=news">News!</a> <br>
<a href="?page=staff">Staff!</a>
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

Steveo31 wrote: We seemed to understand, be nice.
Yea!
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

its just me, i dont understand half sentences. Even if you are only 13, i think you should be able to put together a rather legible and fairly understandable sentence...
Sybatical
Forum Newbie
Posts: 7
Joined: Mon Mar 29, 2004 4:54 pm

Post by Sybatical »

simple php script:
PHP is basically the oposite of SSI, in a way. This time you make the layout first, then you add the content. This is much faster at loading than SSI aswell. If you want to learn PHP, then I suggest that you learn SSI first. If you know SSI, then this will be alot easier to understand. If you wish to continute, simply follow the steps below.

Step 1
First off, make sure your host supports PHP! Angelfire, Geocities and most other free hosts wont but there are some, such as Host Ultra (who suck anyway).

Step 2
Make a layout with no content in it (an empty content area).

Step 3
Look for the place in your html you want the content to appear at and insert the following code:
<?php include ("$id"); ?>

Step 4
Save that page as main.php

Step 5
Now you have to create a page with just content, and no layout. You can call it whatever you want. In this case, we called it linkus.txt

Step 6
Upload both of these pages to your host and type in this url, http://www.yourhost.com/main.php?page=linkus.txt
NOTE: Dont forget to replace http://www.yourhost.com/ with your hosts URL!

Step 7
Go to that page and check to see if it is working correctly. It should work first time if you followed the instructions correctly.
RavenMist
Forum Newbie
Posts: 3
Joined: Mon Mar 29, 2004 5:41 pm

Post by RavenMist »

I am dislexic
:p

<quote>
if(isset($_GET['page']){
$page = $_GET['page'];
switch($page){
case 'home':
echo 'This is the home page.';
break;
case 'other':
echo 'this is another page..';
break;
}
} </quote>

Now the part that says

<quote> case 'other':
echo 'this is another page..';
break; </quote> Is that actually nessary, like will i need to add that part there for every page i have?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

how is that supposed to work? Do you mind explaining how that will work?? Because i'll bet anything that it wont work, if you follow those steps.
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

theres only a small error in the steps

change
Step 3
Look for the place in your html you want the content to appear at and insert the following code:
<?php include ("$id"); ?>
TO
Step 3
Look for the place in your html you want the content to appear at and insert the following code:
<?php
if(isset($_GET['page'])
{
include ($_GET['page']);
}
?>
:!: BUT!!!WARNING that is very VERY INSECURE!!!! so watch out...!!!! :!:
Last edited by PrObLeM on Mon Mar 29, 2004 6:03 pm, edited 1 time in total.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

RavenMist, say you have 3 links:

Code: Select all

&lt;a href="?page=home"&gt;Home&lt;/a&gt;
&lt;a href="?page=downloads"&gt;Downloads&lt;/a&gt;
&lt;a href="?page=contact"&gt;Contact&lt;/a&gt;
Then your switch would look something like this:

Code: Select all

if(isset($_GET['page']){
  $page = $_GET['page'];
  switch($page){
    case 'home':
      echo 'This is the home page.';
      //or if you have a main homepage you can do like:
      //include("home.html");
    break;
    case 'downloads':
      echo 'this is downloads page..';
      //include("downloads.html");
    break;
    case 'contact':
      echo 'this is contact page.';
      //include("contact.html");
    break;
  }
}
Post Reply