Hi, i've been looking for a way to have all my site pages into one
http://mysite/mypage/index?view=home or view=downloads..etc
how would i go about doing this? I'm really novice at this. To see an example of what i want, here are two links that are on one page, but are diffrent
http://nwvault.ign.com/static.php?page=contact
http://nwvault.ign.com/static.php?page=addcontent
Hi phpnoob07,
Welcome to TSDN!
If I understand you correctly what you are after is one url index.php to load many different pages within your site based on the query string, is that correct?
If I am correct then you need to use the query string as you have done above for each link to the page. Then on the page, static.php have code such as this:
-
<?php
-
// this is psuedo code really - but the structure is fine
-
-
/ default page header stuff
-
-
if (empty($_GET['page']))
-
{
-
$lcPage = 'default';
-
}
-
else
-
{
-
$lcPage = $_GET['page'];
-
}
-
-
switch($lcPage)
-
{
-
case 'contact':
-
// include the contact page from a separate file
-
break ;
-
case 'downloads':
-
// include the downloads page from a separate file
-
break ;
-
case 'addcontent':
-
// include the addcontent page from a separate file
-
break;
-
default: // the catch all else - ensures that what ever is in the QS the visitor will be directed here if it's not valid
-
// include the main default page from a separate file
-
break;
-
}
-
// defult page footer stuff
-
?>
-
Each page you wish to have can be built into a separate file and then loaded via the include() function.
Remember php is a case sensitive language so if the url says 'addContent' the switch statement must also say addContent.
As a point of personal preference I prefer to use numbers on the end of the query string, there's no real advantage that I know of it's just the way my brain works.
Hopefully this will have set you of on the right track. If you have any more questions just drop back here anytime.
Cheers
nathj