Drags111 Posted May 17, 2009 Share Posted May 17, 2009 Hello there! im making my first website, and i have a quick question. What I want to do is have a php script load the info for a navigation bar that i have and i want the php to display the navigation bar inside the page. Like for instance, i have a file called navbarinfo.whatever and the script loads that and displays the nav bar using the info found there. This way i wont have to change the nav bar on every html page i have when i add a new section. I'm positive this is possible, how do i do it? Much thanks! -Justin Quote Link to comment https://forums.phpfreaks.com/topic/158491-solved-loading-info-to-place-inside-div/ Share on other sites More sharing options...
lonewolf217 Posted May 17, 2009 Share Posted May 17, 2009 <?php include 'navbarinfo.php'; put the code for the navigation bar in the navbarinfo.php page and then just include it on every page you want the titlebar to be on Quote Link to comment https://forums.phpfreaks.com/topic/158491-solved-loading-info-to-place-inside-div/#findComment-835857 Share on other sites More sharing options...
Drags111 Posted May 17, 2009 Author Share Posted May 17, 2009 Can i do the code in html in the navbarinfo.php page? Quote Link to comment https://forums.phpfreaks.com/topic/158491-solved-loading-info-to-place-inside-div/#findComment-835863 Share on other sites More sharing options...
wildteen88 Posted May 17, 2009 Share Posted May 17, 2009 Yes. You can place HTML code within included files. Quote Link to comment https://forums.phpfreaks.com/topic/158491-solved-loading-info-to-place-inside-div/#findComment-835867 Share on other sites More sharing options...
Drags111 Posted May 17, 2009 Author Share Posted May 17, 2009 ok so i tried it out and i made a php file called mainnav.php with this code: <h1 class="mnh"> <a href="index.html" class="mnlink"><b>HOME</b></a> </h1> <div id="headervr"></div> <h1 class="mnh"> <a href="/comedy/index.html" class="mnlink"><b>COMEDY</b></a> </h1> <div id="headervr"></div> and in the section where i belongs i put <div id="headerdiv"> <h1 class="headerh"> <b>jdubya</b> </h1> <h1 class="com"> .com </h1> <div id="headerhr"> </div> <?php include("mainnav.php"); ?> </div> Its working, however. It just doesnt show up. Can anyone see what i'm doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/158491-solved-loading-info-to-place-inside-div/#findComment-835872 Share on other sites More sharing options...
wildteen88 Posted May 17, 2009 Share Posted May 17, 2009 Make sure you have saved your code to a .php file not .html PHP code by default only works within .php files. Howver files that are include/require'd can have any file extension Quote Link to comment https://forums.phpfreaks.com/topic/158491-solved-loading-info-to-place-inside-div/#findComment-835875 Share on other sites More sharing options...
Drags111 Posted May 17, 2009 Author Share Posted May 17, 2009 both sides to a php file? Because the main one right now is a .html. the nav bar info is in a .php Quote Link to comment https://forums.phpfreaks.com/topic/158491-solved-loading-info-to-place-inside-div/#findComment-835878 Share on other sites More sharing options...
Drags111 Posted May 17, 2009 Author Share Posted May 17, 2009 Oh ok, i figured it out! Thank you very much wildteen! You're a great help! Quote Link to comment https://forums.phpfreaks.com/topic/158491-solved-loading-info-to-place-inside-div/#findComment-835883 Share on other sites More sharing options...
wildteen88 Posted May 17, 2009 Share Posted May 17, 2009 both sides to a php file? Because the main one right now is a .html. the nav bar info is in a .php Yes the main file that includes the navbar needs to be in a .php file. However the file the navbar is in can have any file. Quote Link to comment https://forums.phpfreaks.com/topic/158491-solved-loading-info-to-place-inside-div/#findComment-835890 Share on other sites More sharing options...
Drags111 Posted May 17, 2009 Author Share Posted May 17, 2009 one problem is that i would have to put that file in each directory. when i just do include(whatever) in a directory thats lower than the file, it does not find it. :/ Quote Link to comment https://forums.phpfreaks.com/topic/158491-solved-loading-info-to-place-inside-div/#findComment-835919 Share on other sites More sharing options...
wildteen88 Posted May 17, 2009 Share Posted May 17, 2009 Place mainnav.php in your sites root folder (where you upload your sites content too). Now use include($_SERVER['DOCUMENT_ROOT']."/mainnav.php"); PHP will now always include mainnav.php from your sites root folder no matter where its included from. Quote Link to comment https://forums.phpfreaks.com/topic/158491-solved-loading-info-to-place-inside-div/#findComment-835922 Share on other sites More sharing options...
Drags111 Posted May 17, 2009 Author Share Posted May 17, 2009 Wow ur a genius Thank you so much wildteen! Quote Link to comment https://forums.phpfreaks.com/topic/158491-solved-loading-info-to-place-inside-div/#findComment-835926 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.