使用PHP进行基本导航



We have a school project with HTML/PHP, and we need to create a web page. The problem is there can only be a index (or a main page), the rest of them are small portions of code in other .html documents.

I need to find a way to create a function (I think...) so when I click on one of the links, this will change the <body id>, the <title>, and will load a different content in a <div> (the small portion of code).

Resuming: there are 5 categories, when clicked, each one of them should change the <body id> attribute, the <title>, and load a different .html page in the <div>. I'm sorry if some of you find this offensively lame, but I really need some help with this.

Until now, this is what i have:

<?php
    $id0="" . $id1;     //default
    $id1="home";
    $id2="iso";
    $id3="lm";
    $id4="par";
    $id5="itasir";
    $id6="fh";
?>

<body id="<?php echo $id0; ?>">

Where $id1-6 should be the categories, and the id0 would be the counter or a pointer of the page that should be loaded. Ex. When I click on the "Par" link, $id0 would change to "" . $id4; and the body would load the id0 which contains id4 now... i think... That should be it.

Thanks...

A few things to read – learning is awesome, but of course just being given the code sucks.

<?php
    $id0="" . $id1;     //default
    $id1="home";
    $id2="iso";
    $id3="lm";
    $id4="par";
    $id5="itasir";
    $id6="fh";
?>

Would make much more sense as:

<?php
    $id = array();
    $id[0]="" . $id[1];
    $id[1]="home";
    $id[2]="iso";
    $id[3]="lm";
    $id[4]="par";
    $id[5]="itasir";
    $id[6]="fh";
?>

That way you can easily use numbers to get the one you need.

You are probably going to use variables in the URL using $_GET.

If the URL is http://www.example.com/index.php?page=1, then $_GET['page'] would be equal to 1.

That lets you write some PHP that does different things based on the URL.

You will then likely use file_get_contents (http://php.net/manual/en/function.file-get-contents.php) to load in the contents of the right file.

Easy!