Forum Moderators: coopster

Message Too Old, No Replies

New to PHP, little question

         

bivium

11:32 pm on Sep 10, 2004 (gmt 0)

10+ Year Member



Hi, I'm biulding my new site on PHP and I have a question. Ok, I'm creating my site by making index.php the following:

<?php
require('header.php');

$page = $_GET['page'];
if (($page == "home") or ($page =="")) {
include('home.php');
} else if($page == "guestbook") {
include('content/guestbook.txt');
}

....

else if($page == "domain") {
include('content/domain.txt');
} require('footer.php');
?>

adn all my links and everything is working fine so far. I have one question. Within my sections there are some subsections. Under domain for example, there could be hosting, history, and hosted. Is there any way that instead of adding the subsections to $page, that I can create a new variable ($id for example) so that the site is easier to control? so (and I'm guessing here) that the link is something like:
index.php?page=domain?id=hosting
I'm pretty sure that I can't do what I wrote above, but just for the sake of clarification. Hope someone can help me. thanks:
bivium

Adrian2k4

12:04 am on Sep 11, 2004 (gmt 0)

10+ Year Member



i think this would be the simplest way of doing this:

<?PHP
require('header.php');

$page = $_GET["page"];
$id = $_GET["id"];

if ($page == "") {
include("home.php");
} else {
include("$page.txt");
}

// do something with your category id saved in $id
// for example: underline the category link to show the user
// he is in that category.

?>

Best regards
Adrian

bivium

3:34 pm on Sep 11, 2004 (gmt 0)

10+ Year Member



Thanks! that does make my code much shorter. The reason for my question was that I wanted to put the subsection text files in a different directory:

content/ 
domain.txt
design.txt
domain/
hosting.txt
hosted.txt

so $id would serve as the variable for the subfolders (domain in this case)... but I guess that is just making my life harder? well just wondering, the help you gave me helps me tons... thanks!
bivium