Hey, I have a solution to what I believe your problem is, but there has been a lot of confusion in the thread, so i'll re-write the problem specification first, if it IS what you want to do, read the solution, otherwise, may as well ignore it.
Problem: [i]I want to use the 'include' command to display files within a php page, dependent on appended links (ie index.php?[some code]).[/i]
Solution:
[i]First of all, lets start off with the main file.
On this sort of dynamic website, each logical 'section' of your website (we'll only use one in this example) only has one 'page' that is viewed. We'll call this [b]index.php[/b]. This page may or may not have any [/i]static [i] html, but let's assume you have two things that will change depending on the 'extra stuff' in your links.
This means that no matter what, the user will always be on [b]index.php[/b]. So to change the content on each site, we make use of what are called appended links. Appended links consist of a domain, path and then 'extra' stuff. Like:
[url]www.mySite.com/index.php?id=home[/url]
The path is [b]/index.php[/b] and the extra stuff is [b]id=home[/b]. The extra stuff is added on with the use of a question mark.
To make the page, first off create an HTML page, so you know where everything will go and how it all fits together. Then find an area where you want the content to change. This is normally inside a specific table cell or specific div in pages, if you use them, but it can be anywhere.
Now, look at this section where the content will change, create three separate php files, and in one of them, copy the content that is CURRENTLY in this section. Then write two alternative pieces of content to go in this section. Put them one in each file. (note: the content in these files, can be fully HTML formatted but often it is also just text. Do not put any <html> or <body> tags or anything in it though).
So now you have three pages of content, and an empty content section in your main page. This is where we bring in the link to the page. In the link I posted above, you might have noticed that id=home, almost looks like a variable, but without the $. That's because it is a variable, you can access this variable in your program simply by using $id.
Notice in the link in your browser at the moment, there is a variable 'threadid=87493', to access this in the page, you just use $threadid.
It should now be pretty obvious what you're going to do. It's up to you whether you use [b]switch[/b] or a series of [b]if[/b statements.
Although I would use switch, more people know about if than switch, so i'll use if.
Now, go to the 'content' section of your index.php page that you found earlier. Insert code like this:
[PHP]<?php
$id=$_GET['id'];
if($id=='home') { include("file1.php"); }
else if($id=='news') { include("file2.php"); }
else if($id=='help') { include("file2.php"); }
?> [/PHP]
That's a nice simple version of it. And i'm sure you can work with that to make dynamic pages, but i'll say one more thing about it.
What if the user just goes to [url]http://www.mySite.com[/url] ? The server will (if it's set up that way) default to index.php, but as you can see there is no variable there, so we can modify this program to check if the variable $id has been set. If it has not, we'll include file1.php.
[PHP]
<?php
$id=$_GET['id'];
if(!isset($id)) //if $id has not been set
{
include("file1.php");
}
else if($id=='news') { include("file2.php"); }
else if($id=='help') { include("file3.php"); }
?>
[/PHP]
[/i]
Ok, well I would go on, but I don't even know if that was the question you were asking. If it was, then I hope it helped and feel free to ask questions, if it wasn't, then...oops ::classic:
Edit: If you want to use more than one variable in a link, separate them with & like so:
index.php?id=home&password=bobsyouruncle
Edit#2: Yeah, it doesn't necessarily have anything to do with a database, although you can use them if you want, like:
[PHP]
<?php
$id=$_GET['id'];
$connection=mysql_connect("localhost","averagewhiteband","towerofpower");
$select_database=mysql_select_db("stevie_wonder");
$query=mysql_query("SELECT*FROM pages WHERE page_name=$id");
$page=mysql_fetch_array($query);
if(!isset($id)) { echo "This is default content...do what you like here"; }
else { echo $page; }
?>
[/PHP]
Sorry if some of the database stuff there is wrong....lol, it's been a while since i've done any real PHP.
else:rolleyes:
Edit#3: I added $_GET into the equation, as ShuanTobias reminded me that global vars may be switched off on some servers. You can find out if yours are or not by using phpinfo.
Last edited by Avantasia, December 8th, 2004 01:57 AM (Edited 1 times)