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> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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> Quote Link to comment 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 Quote Link to comment 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/ Quote Link to comment 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)) ?> Quote Link to comment 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. Quote Link to comment 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.