More on PHP subpages

liunx

Guest
I am working on my site (<!-- m --><a class="postlink" href="http://jasonwebb.hostburst.com">http://jasonwebb.hostburst.com</a><!-- m -->), and I want to incorporate a subpage system, ie, index.php?page=page, but I am at a (humongous!) lose as to what exactly to do. I read and even bookmarked the *earlier thread* (<!-- m --><a class="postlink" href="http://www.htmlforums.com/showthread.php?threadid=15524&highlight=navigation+php">http://www.htmlforums.com/showthread.ph ... gation+php</a><!-- m -->) about subpages, and I think I understand the PHP code itself (somewhat, having just gotten motivated to start learning it Friday night), and to save you all the trouble, below you will see the script I wish to incorporate:


<?php
// Grab the page requested:
$requested = (empty($p))?"":$p;
$requested = (empty($_GET["p"]))?$requested:$_GET["p"];

// Print the page:

if ($requested == "page1") {

echo <<<ENDOFPAGE
...
page1 in here
...

ENDOFPAGE;

}
else if ($requested == "pagexyx") {
echo <<<ENDOFPAGE
...
page in here
...

ENDOFPAGE;

}


else {
// last resort, nothing has been printed yet

echo <<<ENDOFPAGE
...
No valid page requested!
...

ENDOFPAGE;

};

?>



Now then, here's what I DO understand

  • "p" is the part that seperates the index.php from the page
    "if ($requested == "page1")" means that page1 is what comes after the ?p, like, index.php?p=page1
    [/list=a]
    That's pretty much it. I need to know;

    1. Where this all goes in a .php file (I am using mostly HTML, with PHP scripts here and there for convience, such as <? include ("yada.html"); ?>...ok, ONLY the <?include?> tag lol...
      What the heck goes on with this all?
      [/list=1]

      A thorough tutorial type answer would be nice, but troubleshooting would be fine too, I just want to understand how all this works, and keep in mind, I am not a heavy PHP programmer right now, I am mainly using it for cosmetic purposes.all you have to do is if your query string is like index.php?p=page1 or ?p=page2 is

      $requested = $_GET['p'];
      if($requested == "page1"){
      include ("page1.html");
      }
      elseif($requested == "page2"){
      include ("page2.html");
      }So...does that....ok...when I want to say, link an image, I


      <a href=http://www.htmlforums.com/archive/index.php/"???"><img src="pic.gif" border=0></a>


      Where does that PHP fit in? I have more than one link I need to use this for...so...how? Sorry for being a dult, but this is completly new to me.<a href=http://www.htmlforums.com/archive/index.php/"index.php?page1"> ?Alright, awesome, we're making progress haha.

      For the PHP code, where does it go? At the top, bottom, in the <head></head> section? I know it's server side, so does it really matter?

      And since I have more than one page, do I:


      $requested = $_GET['p'];
      if($requested == "page1"){
      include ("page1.html");
      }
      elseif($requested == "page2"){
      include ("page2.html");
      }
      elseif{$requested == "page3") )
      include ("page3.html");
      }


      Just keep on adding pages, that I want to it? I mean, can I just keep adding elseif statements for each page I want to include?you dont really need to have any html on that php page

      $requested = $_GET['p'];
      if($requested == "page1"){
      include ("page1.html");
      }
      elseif($requested == "page2"){
      include ("page2.html");
      }
      elseif{$requested == "page3"){
      include ("page3.html");
      }
      else{ //default page if no $requested
      include ("default.html");
      }


      unless you are going to use it kinda like you would frames, to where it would display certain things from an html file in a certain part on the page. then you would do that wherever you would want it to be displayed.Hmm...that's confusing lol.

      I basically am trying to create a scenario that lets me link to pages in the "index.php?page=page1" format, on this page:

      <!-- m --><a class="postlink" href="http://jasonwebb.hostburst.com">http://jasonwebb.hostburst.com</a><!-- m -->

      Will I have to make a whole new PHP file, the new index.php, and have it only have that code you have shown me inside of it? And when you type in that URL you get that page you see right now?

      I guess what I'm saying is, I want to have that page that you see when you go to that URL above simply have the links being index.php?page=page for each page stemming off of it.yeah, make a new one thats like the code posted. it should work fine.Alright! I think I understand! I have school to go to, but now I'm dying to come home and work on this, thank you very much for explaining this to me :)

      btw, I love your avatar, that was one of my favorite shows! That is, of course, if you picked it knowing what it was.furi-kuri! only one of the best animes ever made


      its supposed to be an avatar that randomly picks between 5 pics and displays it, but this forum doesnt just use the link, it uses an html forums link so it only display one of the pics :-/lol, yeah! FLCL was definatly one my favorites, only because NO ONE who isn't an anime fan has no clue what is going on lol...I loved that South Park skit they did lol.

      Strange how that works, I bet they are all cool anyway though.Sorry to double post, but I got problems:

      Parse error: parse error, unexpected '{', expecting '(' in /home/h4t/public_html/professional/index.php on line 9


      That's the error I get now, just trying to load the page that has only


      <?
      $requested = $_GET['p'];
      if($requested == "resume"){
      include ("resume.php");
      }
      elseif($requested == "portfolio"){
      include ("portfolio.php");
      }
      elseif{$requested == "projects"){
      include ("projects.php");
      }
      else{ //default page if no $requested
      include ("main.php");
      }
      ?>


      I added the <? part because it would just give you all that above in plain text on the page if you typed it in...I know it's simple, but I've never used PHP before, so how do I make that proper code?on this line

      elseif{$requested == "projects"){

      you have a { in there instead of a (

      do this

      elseif($requested == "projects"){
 
Back
Top