claffin Posted March 16, 2009 Share Posted March 16, 2009 Hey, I feel a bit stupid asking this question but i've drawn a blank im using the include function to make a website having heading/nav/footer but I cannot for the life of me remember the code thats needed to open the links in the nav bar in the main section i remember doing it years ago but just cant seem to remember now. http://handweaving.seitservices.com.au/index3.php is the site im testing it on. I know the main.php isnt suppose be that just cant remember what it is suppose to be. Here is what I have. <table border="1" width="100%" height="0"> <tr> <td height="120" width="100%" colspan="2"><?php include('heading.php');?> </td> </tr> <tr> <td height="0" width="20%"><?php include('leftmenu.php');?> </td> <td height="0" width="80%"><?php include('main.php');?> </td> </tr> <tr> <td height="50" width="100%" colspan="2"><?php include('bottom.php');?> </td> </tr> </table> leftmenu.php (not suppose to be what it is either) <a href="../index.php">Home</a><p> <a href="../aboutus.php">About Us</a><p> <a href="../products.php">Products</a><p> <a href="../gallery.php">Gallery</a><p> <a href="../contactus.php">Contact Us</a><p> Link to comment https://forums.phpfreaks.com/topic/149622-solved-website-include-function/ Share on other sites More sharing options...
claffin Posted March 16, 2009 Author Share Posted March 16, 2009 another way to explain it would be When clicking the links on the navbar i would like the corresponding page to open up in the main section. Link to comment https://forums.phpfreaks.com/topic/149622-solved-website-include-function/#findComment-785699 Share on other sites More sharing options...
suma237 Posted March 16, 2009 Share Posted March 16, 2009 check this url http://www.bleepingcomputer.com/forums/topic55647.html ,may be this will help you. Link to comment https://forums.phpfreaks.com/topic/149622-solved-website-include-function/#findComment-785700 Share on other sites More sharing options...
Kalland Posted March 16, 2009 Share Posted March 16, 2009 Hi! You must change the links and pass the page names through them. And then fetch the value and store it in a variable, $page. You should also have an array with all you files and check the array up against the value returned by the url. Hope this helps you out. Then you must change this: <?php include('main.php');?> To this: <?php include($page);?> Here is the code i came up with: <?php $page = 'main.php'; // Default page $pages = array('main', 'aboutus','products','gallery','contactus'); // Check if p is set if(isset($_GET['p'])) { // Check if the page in the url is in the defined array if(in_array($_GET['p'])) { $page = $_GET['p'].'.php'; } else { $page = 'main.php'; } } ?> <table border="1" width="100%" height="0"> <tr> <td height="120" width="100%" colspan="2"><?php include('heading.php');?> </td> </tr> <tr> <td height="0" width="20%"><?php include('leftmenu.php');?> </td> <td height="0" width="80%"><?php include($page);?> </td> </tr> <tr> <td height="50" width="100%" colspan="2"><?php include('bottom.php');?> </td> </tr> </table> In your leftmenu.php you must change your links to: <a href="../index.php?p=main">Home</a> Link to comment https://forums.phpfreaks.com/topic/149622-solved-website-include-function/#findComment-785702 Share on other sites More sharing options...
suma237 Posted March 16, 2009 Share Posted March 16, 2009 Use ajax, so that the page won't refresh.http://www.w3schools.com/PHP/php_ajax_database.asp Link to comment https://forums.phpfreaks.com/topic/149622-solved-website-include-function/#findComment-785704 Share on other sites More sharing options...
claffin Posted March 16, 2009 Author Share Posted March 16, 2009 Ok i have put the following code in index.php <head> <title>test</title> </head> <body> <?php $page = 'main.php'; // Default page $pages = array('main', 'about','products','gallery','contact'); // Check if p is set if(isset($_GET['p'])) { // Check if the page in the url is in the defined array if(in_array($_GET['p'])) { $page = $_GET['p'].'.php'; } else { $page = 'main.php'; } } ?> <table border="1" width="100%" height="0"> <tr> <td height="120" width="100%" colspan="2"><?php include('heading.php');?> </td> </tr> <tr> <td height="0" width="20%"><?php include('leftmenu.php');?> </td> <td height="0" width="80%"><?php include($page);?> </td> </tr> <tr> <td height="50" width="100%" colspan="2"><?php include('bottom.php');?> </td> </tr> </table> </body> and in leftmenu.php <a href="../index.php?p=main">Home</a><p> <a href="../index.php?p=about">About Us</a><p> <a href="../index.php?p=products">Products</a><p> <a href="../index.php?p=gallery">Gallery</a><p> <a href="../index.php?p=contact">Contact Us</a><p> you can see results at http://handweaving.seitservices.com.au/ Link to comment https://forums.phpfreaks.com/topic/149622-solved-website-include-function/#findComment-785717 Share on other sites More sharing options...
Kalland Posted March 16, 2009 Share Posted March 16, 2009 Oh, try this. This: <?php if(in_array($_GET['p'])) ?> Should be: <?php if(in_array($_GET['p'], $pages)) ?> Link to comment https://forums.phpfreaks.com/topic/149622-solved-website-include-function/#findComment-785719 Share on other sites More sharing options...
claffin Posted March 16, 2009 Author Share Posted March 16, 2009 marvelous thanks for the help I shall never forget it again lol. Link to comment https://forums.phpfreaks.com/topic/149622-solved-website-include-function/#findComment-785722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.