Jump to content

Show content with HTML menu


guillermo15

Recommended Posts

Hi !

 

I'm a newbie to PHP... did a few tutorials and tested many exemples!

I've searched many forums (including this one) and can't seem to get it right ! I'm trying to put a name on my query...

 

I have an index.php that 'include' parts of my page (header, footer, etc.) and an html menu made of <li> also included in this page. Looks like this :

<?php

$filename = "home";

include("header.php");

  include ("menu.php");

include ("content"); // relative to the page

include ("footer.php");

?>

 

 

My content (a central <div> in the site) is called with URLs (<a>) in this menu. However, I'm trying to have a single PHP page and have my current menu controlling the central content. I have tried the 'case' option but it's not "pretty" enought. I want to keep my <li> menu (worked so hard on the CSS...)

 

As you can see, I have given a variable name to each page (here $filename = "home"; ) and copied this code to every page (about 20 pages) giving a new variable name for each. I finally built a "content" page that include all possible contents with "if $filename echo 'html content'".

 

Also, my menu is filled with 'if's else's' that change the (<li>) look. Exemple :

if($filename =="home")

/{

echo "<li><a href=index.php'><font color='#007F55'>Home</font></a></li>";

}

else {

echo "<li><a href='index.php'>Home</a></li>";

}/

 

So my site looks like :

 

20 php pages including a content.php that calls with if $filename is... a //<div>// html page with proper content.

 

My question :   Now I want to have a single index.php page and mutliple content page (with only the <div>) that will be called by my <li> menu.

Can somone point me in the right direction ?

Link to comment
Share on other sites

i'm a little lost, but hey, what's new!

 

Are you wanting one page does all?

 

If so you've basically got two options, but both work the same way in the end.

 

You have your link and to this you append a GET statement, e.g. 'index.php?page=home', then in the page you extract the GET statement using:

$page = $_GET['page'];

This can then be used to fetch content to put in you body section...

 

The other way is basically exactly the same but you use mod_rewrite and then a link such as 'home.html' would get translated into 'index.php?page=home' automatically.

 

(But i'd get the first bit working before spending time on mod_rewrite)

Link to comment
Share on other sites

Thanks !

 

Lets say I feel really stupid and need a little more explanation (Tried the _GET but can't get it to work properly)

 

Thats the site I'm building :http://www.eloflo.com

You were right, I want a one page does all but center content changes.

 

Now this page is 3 includes (header, footer, menu )and the content. So I created all pages.php similar except for the center (content) part.

 

Now, if I want all my pages to be only the code for the center and the menu's links to modify this content, correct me if i'm wrong :

 

my links would all have to be

index.php?page=(variable name for this content)

right ?

 

and the beginnig of all my content pages would be

$page = $_GET['variable name for this content'];

 

I'm all messed up...

 

Link to comment
Share on other sites

There know to be key / value pairs, just like associated arrays (and that's what $_GET is).

index.php?key=value

then

$key = $_GET['key'];

 

if your dealing with forms then you'll use $_POST instead, however $_REQUEST looks in both (and also $_COOKIE).

 

To view a whole set use (substitute global array for whichever):

foreach ($_SERVER as $k => $v)
{
echo $k.": ".$v."<br>";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.