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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about Index.php?page=1

Status
Not open for further replies.

orceht

Technical User
Nov 14, 2006
9
hello i'm new to php.

i was wondering how other sites do this, they have index.php and then question-mark "?" and then page=1

so it looks index.php?page=1 or index.php?page=aboutus

can anyone help me if you understanded ...
 
ok i have index.php page which is normal plain html page

i want to have link index.php?page=aboutus so when you click on it it opens the page=aboutus... i dont know how to do it..
 
There are several ways to do it.

The basic idea is you take the value of your page variable, "page" and depending on it you load content into the page.

For instance, if you content is in a DB: you would take the page value and generate a query that would retrieve the content of the "aboutus" page.

you could also do it using includes. so you would include the file with the name aboutus.php or the file named 1.php depending on the value of your variable.





----------------------------------
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.
 
how to make content inside DV please help me i'm new or point me t o some tutorials, the first option i'd like to use vacunita
 
You have a Database (DB) that has your content? or you want your content to appear inside a DIV in your page?


For Content that is stored in a Database have a read here:





----------------------------------
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.
 
I want content to appear inside a DIV in my page
 
O.k, so where are you going to get the content from?

Is it from other html files?

You can do something like:


Code:
<div id="content">
<?PHP
if($_GET['page']=="aboutus"){
include ("path\to\aboutus.html");
}
?>
</div>

Where page is the name of the variable you use in your link like index.php?[red]page[/red]=aboutus

Just keep adding if's if you have more pages, and you can add a default include if there is no value passed. That is if s the first time the open the page, and no link has been clicked.

----------------------------------
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.
 
vacunita, thank you for that, it works but when i open as you said above, index.php?page=aboutus, in the about us page, it is ok, good looking but at the end it shows this link where i clicked previously ... how to avoid that? thanks
 
try this. delete your index.php and replace it with just this

Code:
<?php

if(isset($_GET['page'])){
	$page = trim($_GET['pge']);
} else {
	$page = 'default';
}
?>
<html>
<body>
<div>
	this is a header div where you put information that you want repeated on every page
</div>
<div>
<?php include $page.".php"; ?>
</div>
<div>
	This is a footer div where you put information that you want repeated on every page
</div>
</body>
</html>
<?php exit();?>
then create files called aboutus.php, default.php etc that contain the content that you want to appear in the middle div.

if instead you want the middle div content to come from a database then use the value of the $page variable to query the database and output the value in that div rather than using an include.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top