synking Posted January 24, 2009 Share Posted January 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142256-solved-flat-file-navigation/ Share on other sites More sharing options...
NorthWestSimulations Posted January 24, 2009 Share Posted January 24, 2009 <?php $page = $_GET['page']; if ($page == NULL){ include_once('pages/home.php'); } elseif (file_exists('pages/'.$page.'.php')){ include_once('pages/'.$page.'.php'); } else include_once('pages/error404.php'); Should work. Good luck with your website my friend Quote Link to comment https://forums.phpfreaks.com/topic/142256-solved-flat-file-navigation/#findComment-745269 Share on other sites More sharing options...
.josh Posted January 24, 2009 Share Posted January 24, 2009 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/142256-solved-flat-file-navigation/#findComment-745274 Share on other sites More sharing options...
synking Posted January 24, 2009 Author Share Posted January 24, 2009 swwweeet thanks guys i was way over thinking it. Quote Link to comment https://forums.phpfreaks.com/topic/142256-solved-flat-file-navigation/#findComment-745279 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.