Welcome to WebmasterWorld Guest from 3.227.254.12

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Include for site navigation. sorry

     
6:21 am on Aug 14, 2006 (gmt 0)

New User

10+ Year Member

joined:Apr 1, 2006
posts:31
votes: 0


Sorry, I know this has been gone over a thousand times, but I can't seem to get this to work.

I have a basic HTML site with CSS and a navigation section on the right that I'd like to turn into a PHP include, so that I don't have to edit every page when I add a new article.

Here's how this section of page.html goes:

<div id="right">
<?php
include("right.php");
?>
</div>

right.php goes like this:

<html>
<body>
<h6 align="center">articles</h6>
<p><a href="article1.html">Article One</a></p>
<p><a href="article2.html">Article Two</a></p>
<p><a href="article3.html">Article Three</a></p>
<h6 align="center"><a href="links.html">Online Resources</a></h6>
</body>
</html>

All of the files are in the same directory.

Now, when I pull up page.html, everything looks fine but this section of the code, where the right nav bar is just a black line, obviously created by the 1pt black outline of #right in style.css.

I have a feeling that there's something fundamentally wrong in the code of right.php (should it have "<?php...?>" even if there's no PHP in the file?; do I need the <html> and <body> codes?)...

Theoretical question: does every .php file need to start with <?php?

Sorry for the stupid newbie question, but I've found myself geting lazy with my site (one page per day, as Brett's bible says). It's just too hard if I have to download a hundred html pages, update them, then upload them, just to keep my navigation up-to-date.

Thanks for your help.

6:38 am on Aug 14, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 27, 2003
posts:1648
votes: 2


Its not quite right. Try following these steps:
1. create right.php
2. choose one of your current pages (one you havent put an include in yet) lets call it product72.html
3. select the code in product72.html that is exactly what you want duplicated - now cut..
4. change files to right.php, paste and save
5. go back to product72.html and paste in
<?php
include("right.php");
?>
and save

and that should be it!

You dont need the <body> and ><html>,etc elements in the include files as they are not pages, they are snippets of markup.

Hope that helps!

6:50 am on Aug 14, 2006 (gmt 0)

New User

10+ Year Member

joined:Apr 1, 2006
posts:31
votes: 0


BTW: I'm using "Learning PHP & MYSQL" by Davis and Phillips (O'Reilly) to learn this stuff. Not for the site in question, but for something I'm thinking of doing in the future.

I'm not having much success with the book. For example, there are quite a few workarounds to get your XP machine to use Apache and PHP, and none of them are mentioned in the book (the method they propose did not work for me, but the Apache Lounge had the answers and the workaround). Also, there are some stupid little things, like 5+3-2 will output "6", not "8" as the book suggests at one point... which can really screw up someone new to this, and make them think, "Am I reading this wrong?" And then a newbie wastes an hour re-reading the book to find out if there's something he's missing.

Anyway, I'd greatly appreciate it if you'd recommend any good resources you know of that are geared for new people. PHP & MYSQL For Dummies is being re-released in December, but I'd like something that's current right now.

Thanks.

7:48 am on Aug 14, 2006 (gmt 0)

New User

10+ Year Member

joined:Apr 1, 2006
posts:31
votes: 0


Thanks, Leadgeroot, but this isn't working. I'll have to revisit this tomorrow and I'll let you know how it goes.
8:17 am on Aug 14, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Mar 30, 2006
posts:333
votes: 0


Don't put the html and body in the php page. All you need is the code.

Ie if you have table tr td in your index.html page.... all you need in .php page is the section from td

Start

<h6 align="center">articles</h6>
<p><a href="article1.html">Article One</a></p>
<p><a href="article2.html">Article Two</a></p>
<p><a href="article3.html">Article Three</a></p>
<h6 align="center"><a href="links.html">Online Resources</a></h6>

End

[edited by: Rightz at 8:27 am (utc) on Aug. 14, 2006]

8:35 am on Aug 14, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 27, 2003
posts:1648
votes: 2


Lets try this another way :)
I have a feeling that there's something fundamentally wrong in the code of right.php (should it have "<?php...?>" even if there's no PHP in the file?;

Nope! You can have several <?php?> blocks through your page or file - it just means 'evaluate the stuff in here for code'. No code means no need for <?php?>

do I need the <html> and <body> codes?)...

*no* - this only gets wrappped around the actual page!

when I pull up page.html, everything looks fine but this section of the code, where the right nav bar is just a black line, obviously created by the 1pt black outline of #right in style.css.p

Are you sure you have php running properly?
To test, create a new file, call it test.php, and put the following code in it:

<?php
phpinfo();
?>

Thats it, nothing more.

Now drop that in your folder where your webpages are and bring it up in a browser.
Do you see pages of guff telling you all your details? Yes means PHP is running properly, No means you arent seeing executed PHP.
Note: you must view the page through the webserver, not just through the file path, so you must be able to view the page as [......] - absolutely crucial. Its the webserver running the PHP, so the page must come from the webserver. Its different to HTML, which the browser looks after.

Another test: in the original page that isn't working, view the markup - do you see the <?php ....?>? If so, PHP isn't being accessed properly, or even isn't running.

5:49 am on Aug 15, 2006 (gmt 0)

New User

10+ Year Member

joined:Apr 1, 2006
posts:31
votes: 0


Thanks for the replies.

leadegroot,

Are you sure you have php running properly?
To test, create a new file, call it test.php, and put the following code in it:
<?php
phpinfo();
?>

This test passes. I see the php info page. I can also access right.php. The only thing that's not working is the include in the html file.

Another test: in the original page that isn't working, view the markup - do you see the <?php ....?>? If so, PHP isn't being accessed properly, or even isn't running.

I do see the <?php...?> code when viewing the source of the html page. The php code is pink when I view it in FireFox.

I talked to my host, and the guy looking at it said that the code looked right and he'd get back to me, after checking if there's a permissions issue or something. But it's also not working on my localhost, and I am accessing it through [localhost...]

Note: I have this code in its own <div> tags in the HTML. Does it need to be in a table <td>?:

...</div>
<div id="right">
<?php
include("right.php");
?>
</div>
<div id="left">...

Thanks for your help.

5:51 am on Aug 15, 2006 (gmt 0)

New User

10+ Year Member

joined:Apr 1, 2006
posts:31
votes: 0


Believe it or not, this is the only page on my site that validates. Maybe that's the problem :-O
7:15 pm on Aug 15, 2006 (gmt 0)

New User

10+ Year Member

joined:Apr 1, 2006
posts:31
votes: 0


oops...

I had to rename the .html file to the .php extension.

Thanks for your help. I knew it was something stupid. Sorry.

1:03 pm on Aug 16, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 27, 2003
posts:1648
votes: 2


Ah, that was going to be my next suggestion.
Yopu can also change the htaccess file so that .html files will be pprocessed for .php
But, as long as its working :)
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members