Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass url as variable

Status
Not open for further replies.

AJParkinson

Technical User
Apr 11, 2003
74
0
0
GB
Please help, php newbie...
How do I achieve the following (I've looked through threads on here and google - nothing has jumped out at me, but then again don't really know what I should be looking for...

I have a template page -> index.php
on this page are text links -> page1.php page2.php etc
also on this template page is a 'content' section where I (wish to) have an include -> <? include("clicked-link-variable.php") ?>

How do I get the template page to reload with the content 'include' name replaced with the link page name ???

i.e. click on page1.php link and template reloads with <? include("page1.php") ?> etc

any help greatly appreciated

Andrew
 
Assuming your links look like this:
Code:
<a href="index.php?page=page1.php">

Then in the include part you would do something like:

Code:
if(isset($_GET['page']
{
include $_GET['page'];
}
else
{
include [green]your default page[/green].
}

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks vacunita for your quick reply, I've just tried the following -
Code:
<!-- in the links section: -->
<div id="links">
<a href="index.php?page=home.php">Home</a> <br> 
<a href="index.php?page=page1.php">Page 1</a> <br> 
<a href="index.php?page=page2.php">Page 2</a> <br>
etc
</div>

<!-- and in the content section: -->
<div id="content">
<?
if(isset($_GET['page']
{
include $_GET['page'];
}
else
{
include ("home.php")
}
?>

</div>

when I test this I get a parse error because of the ; on the
Code:
include $_GET['page'];
line.
I've tried removing it but get a different parse error - unexpected T_ELSE, expecting ',' or ')' on the
Code:
else
line.

can you give me any more help please?

Andrew
 
1.
this results a page error as a url variable.
home.php">
page1.php">
page2.php">
don't use dot(.) in your url variable value.

2.
your if-else statement also results a page error ...
if(statement) ------> always close it.

hope that helps..
 
First, the dot in the file name is irrelevant to the error because its just a string. The error is happening because you are not closing the IF statement.

Code:
<div id="content">
<?
if(isset($_GET['page'][red]))[/red] [green]Youi are missing 2 parenthesis here.[/green]
{
include $_GET['page'];
}
else
{
include ("home.php")
}
?>

</div>

The rest should work itself out.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks vacunita (& wakeendev), got it going now.

Much appreciated

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top