alphamoment Posted November 22, 2015 Share Posted November 22, 2015 I'm using this current PHP Code in my Index.php; <?php $page = $_GET['page']; if (!isset($page)) { include('home.php'); } if ($page == "Home") { include('home.php'); } if ($page == "0101") { include('0101.php'); } if ($page == "0202") { include('0202.php'); } ?> Then I'm using this for my Navigation link; <li><a href="?page=0101">Members</a></li> Which displays as index.php?page=0101 But on those pages I want to go into another page off of them, for example; index.php?page=0101&subpage=0102 index.php?page=0202&subpage=0201 How can I achieve this? Quote Link to comment https://forums.phpfreaks.com/topic/299547-php-nav-function-with-subpage/ Share on other sites More sharing options...
Jacques1 Posted November 22, 2015 Share Posted November 22, 2015 Why do you even need to mention the parent page in the URL? In other words, why can't you just say index.php?page=0102? Isn't the ID of the subpage already unique? By the way, you really need to choose better identifiers for your pages. It might also be a good idea to review the overall architecture of your site. When people start to use weird numbering schemes to organize their pages, that's usually a bad sign (unless this was just an example). 1 Quote Link to comment https://forums.phpfreaks.com/topic/299547-php-nav-function-with-subpage/#findComment-1526928 Share on other sites More sharing options...
mac_gyver Posted November 22, 2015 Share Posted November 22, 2015 you would make use of the same type of page controller logic (the conditional tests) that you have in your main file, within each of the pages that have subpages, to control what they do for any subpage they contribute to the navigation and are responsible for processing. for your example of index.php?page=0101&subpage=0102, the main page controller in index.php will include/require 0101.php. the page controller within 0101.php would test for the existence of $_GET['subpage'] and run/include/require the appropriate code for the 0102 subpage action. 1 Quote Link to comment https://forums.phpfreaks.com/topic/299547-php-nav-function-with-subpage/#findComment-1526937 Share on other sites More sharing options...
QuickOldCar Posted November 22, 2015 Share Posted November 22, 2015 I agree with Jacques. A good way is to save items in a database such as a section or category, article id's or as pretty/safe slugs Using a properly set up relational database to handle what gets shown and when. For instance when selecting a certain "page" you do a query and get all it's related "subpages" What you should have is an index page with a loop of possible "subpages", if and when the GET value is set for "subpage" it should include a single view code or script of just that "subpages" content. Sometimes I create a whitelist array of the pages allowed, other times I'll fetch the required page name from a database because would exist as a dynamic value. You could try doing something like this to simplify your if's if (isset($_GET['page']) && trim($_GET['page']) !='') { $page = $_GET['page']; } else { $page = "home"; } $script = dirname(__FILE__) . DIRECTORY_SEPARATOR . $page . ".php"; if (file_exists($script)) { require_once($script); } else { echo "Page does not exist"; } Then you can check for $_GET['subquery'] within each script 1 Quote Link to comment https://forums.phpfreaks.com/topic/299547-php-nav-function-with-subpage/#findComment-1526938 Share on other sites More sharing options...
alphamoment Posted November 23, 2015 Author Share Posted November 23, 2015 Thank you for the reply. The 0's 1's 2's were just examples. I appreciate the responses as they have helped me greatly! Quote Link to comment https://forums.phpfreaks.com/topic/299547-php-nav-function-with-subpage/#findComment-1526965 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.