Jump to content

[SOLVED] flat file navigation


synking

Recommended Posts

Hey everyone,

 

I am trying to create a flat file navigation menu. what i want is a static navigation menu that will not change in its own div on the left side of the page and then when someone follows the link in will load in a content area to the right. I know how to do this with mysql and php you just create a link that has

<a href="index.php?id='id of page'>Main</a>

and then in the content area of the page you have all of the mysql query stuff to show that page with what is in the database that will reference to that page id.

 

Now i am trying to to do this with a flat file system and i can create the links that part is not hard but how would i get the content page to change like how the mysql way works.

Link to comment
Share on other sites

Without a database you will need to hardcode an id => filename relationship.  You can create a separate textfile with a list and read it into an array or just hardcode an array in your script.  Here is a small example:

 

<?php
$content = array(1 => 'home', 2 => 'about', 3 => 'contact');

echo "<div>";
foreach ($content as $id => $page) {
   echo "<a href='?id=$id'>$page</a> ";
} // end foreach 
echo "</div>";
echo "<div>";

$page = (int) $_GET['id'];
$page = (array_key_exists($page, $content))? $content[$page] : $content[1];

include ("{$page}.php");
echo "</div>";
?>

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.