PDA

Click to See Complete Forum and Search --> : php includes


dyers78
03-05-2007, 03:24 PM
uuummm k -

I am trying to get away from using Golive as a site manager for anything other than the basics. I want to try to use php includes but am having alittle trouble getting it to play nice with my style sheet.

I have my .php file ready with my navigation cleverly named - MainNavi.php which houses my list of links. I copied and pasted the html nav section from the html doc to the php doc. I then placed a <? php include("MainNavi");?> into the html doc where I want to call my php script.

My list of links were styled all pretty before I put them in the separate .php file. how do I style them now that the code is housed in the php file? My original css looked like this:

#nav ul {margin: 0; padding: 0 0 0 30px; }
#nav li {list-style-type: none; font: bold 8pt Arial san-serif; color: #0e2f80}
#nav li a {line-height: 12pt; font-weight: normal }
#nav li a:link {color: #0e2f80; text-decoration: none;}
#nav li a:visited {color: #0e2f80; text-decoration: none;}
#nav li a:hover {color: #999; text-decoration: none;}
#nav li a:active {color: #999; text-decoration: none;}
.mainnavtitles {padding: 10px 0 5px 0;}

obviously I no longer have the ul and li to style because they are in the php script.

John G
03-05-2007, 03:47 PM
?> css <?php

?? I'm a little unclear on what is doing what and where?

dyers78
03-05-2007, 04:07 PM
as am I. I apparently have no clue what I'm doing.

I have a beautiful CSS page. I want to strip my navigation from that page in reinsert it as a php include () but I am not reading this file right.

Correct me if I am wrong.

1. creat a new page named MainNavi.php and place my chunk of html code representing my navigation list into this new page MainNav.php.

2. create a new style sheet (MainNav.css) which MainNav.php will link to in order to make it pretty.

3. Include the code <?php include (MainNavi");?> into the div which will house the final navigation render.

i.e. <div id=MainNavi>
<?php include (MainNavi");?>
<div>

ecsyle
03-05-2007, 04:18 PM
<?php include ("MainNavi.php");?>

You need to include the file extension of the file you are including. You were also missing the first double quote. Be sure that you have error reporting turned on when you are testing and developing.

Place this at the top of your page:


<?php error_reporting(E_ALL); ?>

Benjamin
03-05-2007, 04:21 PM
You need to understand the different stages of how a page is put together by the server.

The HP in PHP stands for Hypertext Pre-processor, which means that everything PHP does happens before you have an actual HTML page.

Basically, including a chunk of HTML code with PHP will just dump that code dierctly into the HTML page at the place where you put the include. So you can leave the same stylesheet in place at the top of the page and it will continue to work as before. It doesn't make any sense to create a separate CSS file for the PHP file.

dyers78
03-05-2007, 04:43 PM
oh cool! makes more sense. I have another question I am stumbling over.

When I create the new php do I structure like a regular old html page or like a script?

Here is my php page (MainNavi.php) currently:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<?php

?>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>MainNavigation</title>
</head>

<body>
<div id="nav">
<img src="img/SiteWide/uw_rgb_ful_qc.gif" alt="United Way logo">
<ul>
<li class="mainnavtitles">Get Involved</li>
<li><a href="#">Calendar of Events</a></li>
<li><a href="#">Rsvp for a Meeting/Event</a></li>
<li><a href="#">Day of Caring</a></li>
<li><a href="#">2006 Campaign Updates</a></li>
<li><a href="#">40 Developmental Assets</a></li>
<li><a href="#">Volunteer Opportunities</a></li>
<li class="mainnavtitles">Community Investment</li>
<li><a href="#">Investment Process</a></li>
<li><a href="#">Tools</a></li>
<li class="mainnavtitles">Partnerships</li>
<li><a href="#">Partner Agencies</a></li>
<li><a href="#">Labor Partners</a></li>
<li><a href="#">Media Alliance</a></li>
<li><a href="#">Caring Club Card</a></li>
<li><a href="#">Gifts In-Kind</a></li>
<li class="mainnavtitles">Communications</li>
<li><a href="#">United Way Logo</a></li>
<li><a href="#">Campaign Tools</a></li>
<li class="mainnavtitles">About Us</li>
<li><a href="#">Staff</a></li>
<li><a href="#">Mission & Vision</a></li>
<li><a href="#">Board of Directors</a></li>
<li><a href="#">Career Opportunities</a></li>
<li><a href="#">Contact Information</a></li>
<li><a href="#">FAQs</a></li>
</ul>
</div>
</body>

</html>


OR do I set it up like a script where the code is up in the php tags in the head?

John G
03-05-2007, 05:26 PM
includes just inserts code, so it doesn't need <body> and <head> or anything like that as long as the required stuff is going to as long as it's included in the page that's doing the loading. It also doesn't need to be named php. it can be html or .tpl or .anything because php doesn't care.

your MainNavi.php could just be

<div id="nav">
<img src="img/SiteWide/uw_rgb_ful_qc.gif" alt="United Way logo">
<ul>
<li class="mainnavtitles">Get Involved</li>
<li><a href="#">Calendar of Events</a></li>
<li><a href="#">Rsvp for a Meeting/Event</a></li>
<li><a href="#">Day of Caring</a></li>
<li><a href="#">2006 Campaign Updates</a></li>
<li><a href="#">40 Developmental Assets</a></li>
<li><a href="#">Volunteer Opportunities</a></li>
<li class="mainnavtitles">Community Investment</li>
<li><a href="#">Investment Process</a></li>
<li><a href="#">Tools</a></li>
<li class="mainnavtitles">Partnerships</li>
<li><a href="#">Partner Agencies</a></li>
<li><a href="#">Labor Partners</a></li>
<li><a href="#">Media Alliance</a></li>
<li><a href="#">Caring Club Card</a></li>
<li><a href="#">Gifts In-Kind</a></li>
<li class="mainnavtitles">Communications</li>
<li><a href="#">United Way Logo</a></li>
<li><a href="#">Campaign Tools</a></li>
<li class="mainnavtitles">About Us</li>
<li><a href="#">Staff</a></li>
<li><a href="#">Mission & Vision</a></li>
<li><a href="#">Board of Directors</a></li>
<li><a href="#">Career Opportunities</a></li>
<li><a href="#">Contact Information</a></li>
<li><a href="#">FAQs</a></li>
</ul>
</div>

I'd rename it something like MainNavi.nav.html or something (php won't care of the file type).

Now, the fiile, the original page, that had the nav in it, but doesn't anymore needs to be renamed php, because it's doing the loading of the page, and the *.php filetype needs to flag the server "hey PHP here". So now that the server knows that your original file is php it'll read it and look for <?php ?> stuff, which has your includes and then it'll look for those files to include and such and insert them into the page.

Another thing to remember. If you load your CSS file into your new index.php page (the one that has the includes) all the CSS is "inherited" and you don't need to load it again. If you load your CSS file after your include that included code won't see the CSS.


*edit: oh god, nav, navi your killing me >.< disregard the stuff you already know.

dyers78
03-05-2007, 06:43 PM
I have nothing. here is the code if anyone can see what I am doing wrong,

Index code (named index.php):


<!DOCTYPE html PUBLIC "‑//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>United Way of the Quad Cities Area</title>
<link href="css/basic.css" rel="stylesheet" type="text/css" media="all" />
<?php error_reporting(E_ALL); ?>
</head>

<body>
<div id="main">
<div id="container">

<div id="heading">

<div id="leftheading">
<h1>United Way<br />of the Quad Cities Area</h1>
<form id="quickLinks" action="#" method="get" name="quickLinks">
<select name="search quicklinks">
<option selected="selected">search site quick links</option>
<option value="two">40 assets</option>
<option value="three">communication tools</option>
</select>
</form>
</div>

<div id="headnav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">InfoLINK/211</a></li>
<li><a href="#">Success By 6</a></li>
</ul>
</div>

</div>

<div id="flashMovie">
<p>Flash Movie Here highlighting what's up.</p>
</div>

<div id="news">

<div id="children">
<h1>Successful<br />Children &amp; Youth</h1>
<p>Learn how United Way is dealing with the root problems concerning area youth through the 40 Assets.</p>
<p><a href="http://www.unitedwayqc.org/html/AssetMicroSite/intro2.html">Be an Asset Builder</a></p>
</div>

<div id="community">
<h1>Caring<br />Community</h1>
<p>Working to promote and encourage volunteerism here in the Quad Cities.</p>
<p><a href="http://www.unitedwayqc.org/html/AssetMicroSite/intro2.html">Volunteer Opportunities</a></p>
</div>

<div id="families">
<h1>Strong<br />Families</h1>
<p>Offering solutions to problems effecting faiies of all types.</p>
<p><a href="http://www.unitedwayqc.org/html/AssetMicroSite/intro2.html">Discover Family Phazes</a></p>
</div>

<div id="reliantPeople">
<h1>Healthy,<br />Self-Reliant People</h1>
<p>Focused on discovering the root causes of poverty and how it effects people.</p>
<p><a href="http://www.unitedwayqc.org/html/AssetMicroSite/intro2.html">Ruby to Present</a></p>
</div>


<div id="mission">
<img src="img/mission.gif" alt="To improve lives and make a positive impact in our community." border="0">
</div>

</div>
</div>

<div id="nav">
<?php include("php/main.nav.html") ?>
</div>

<div id="footer">
<p>copyright 2007 United Way of the Quad Cities Area | Privacy Policy</p>
</div>

</div>

</body>

</html>



and the include code named (main.nav.html):


<img src="../img/SiteWide/uw_rgb_ful_qc.gif" alt="United Way logo">
<ul>
<li class="mainnavtitles">Get Involved</li>
<li><a href="#">Calendar of Events</a></li>
<li><a href="#">Rsvp for a Meeting/Event</a></li>
<li><a href="#">Day of Caring</a></li>
<li><a href="#">2006 Campaign Updates</a></li>
<li><a href="#">40 Developmental Assets</a></li>
<li><a href="#">Volunteer Opportunities</a></li>
<li class="mainnavtitles">Community Investment</li>
<li><a href="#">Investment Process</a></li>
<li><a href="#">Tools</a></li>
<li class="mainnavtitles">Partnerships</li>
<li><a href="#">Partner Agencies</a></li>
<li><a href="#">Labor Partners</a></li>
<li><a href="#">Media Alliance</a></li>
<li><a href="#">Caring Club Card</a></li>
<li><a href="#">Gifts In-Kind</a></li>
<li class="mainnavtitles">Communications</li>
<li><a href="#">United Way Logo</a></li>
<li><a href="#">Campaign Tools</a></li>
<li class="mainnavtitles">About Us</li>
<li><a href="#">Staff</a></li>
<li><a href="#">Mission & Vision</a></li>
<li><a href="#">Board of Directors</a></li>
<li><a href="#">Career Opportunities</a></li>
<li><a href="#">Contact Information</a></li>
<li><a href="#">FAQs</a></li>
</ul>

ecsyle
03-05-2007, 06:44 PM
Are you getting any errors?

dyers78
03-05-2007, 06:54 PM
no. I am using GoLive as my editor but and doing this is code-mode (that sounds cool) anyways, when I go to preview this in Safari it displays the actual source code, which is new to me. and in Firefox it renders properly but my navigation is just not there? I think I am getting close, I can't can't seem to find anything else to try. It all looks good from what I can see.

side note ecsyle - what does that snip-it you suggested earlier actually do?

ecsyle
03-05-2007, 06:57 PM
Unless you have php installed on your computer it's not going to process it. Upload it to a server that has php installed.

It will show you php errors, warnings, and notices. It helps when you are developing to see the errors.
http://us2.php.net/error_reporting

John G
03-05-2007, 06:57 PM
^^^^^
same time post -_-

works when i upload it to my webspace anyways.
where the heck is the delete post...

dyers78
03-05-2007, 07:00 PM
does it display the navigation? I will have to upload this.

dyers78
03-05-2007, 07:50 PM
ok, I got a warning. Never thought I would be so happy about that.


Warning: Failed opening 'php/mainnav.php' for inclusion (include_path='.:/usr/share/pear:/usr/local/php-include:/home/httpd/phplib') in /raid5/local/u1/infolink/html/2007Site/index.php on line 10

Is this just saying that the path is wrong?

ecsyle
03-05-2007, 07:54 PM
Yeah, is mainnav.php in a folder called php? And is the php folder in the same directory as index.php?

Be sure you upload mainnav.php. And if the file is called mainnav.php, all lowercase, you need to be sure that it is all lowercase in your include function too.

dyers78
03-05-2007, 08:31 PM
Cool! thank you all so much. No errors and it is displaying correctly. I have not tested it out on multiple pages yet though.

Let's go have a beer to celebrate on me.