We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,878 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Use Include function - Newbie

Hi All,
Please help me to understand it better. I want to have a simple site with Header, navigation bar, side bar and opposite to side bar, main contents. I want to Include files for this sections in index.php. Here is a thing I dont understand:

---- If I divide index.php using table, how do I make other pages? Should them be full XHTML starting or just simple <div> ----

Thanks for your valuable reply

3
Contributors
3
Replies
1 Hour
Discussion Span
4 Years Ago
Last Updated
4
Views
Question
Answered
Stefano Mtangoo
Senior Poster
3,731 posts since Jun 2007
Reputation Points: 462
Solved Threads: 396
Skill Endorsements: 0

The file is included inline and parsed just like the contents of the file would be if they were placed there instead. A standard include for the content could be something like:
content.php:

<div class="content">
<?php echo $content;?>
</div>

Then the page could be something like:

<?php
//query db and populate $content variable here.
?>
<html>
<head><title>Page</title></head>
<body>
<?php include "content.php";?>
</body>
</html>

The above would display the same output as:

<?php
//query db and populate $content variable here.
?>
<html>
<head><title>Page</title></head>
<body>
<div class="content">
<?php echo $content;?>
</div>
</body>
</html>

You should also consider using includes for things that are common throughout the site, like the navigation menu. This way, if you have 50 pages on the site and you want to add a link to the navigation menu, you only have to change one file, instead of 50.

buddylee17
Practically a Master Poster
699 posts since Nov 2007
Reputation Points: 232
Solved Threads: 137
Skill Endorsements: 1

each included file can be only that part of the html that they need to be
full xhtml for all will give validation errors

<?php
include('doctype.inc.php'); 
echo '<title>'.$pagetitle."</title>";
include('header.inc.php');
include('menu.inc.php');
include("$pagename");
include('footer.inc.php'); ?>

is valid as long as the included files contain the required html (or php to generate the required html obviously) in the required order
there is no requirement for those filenames, that is the code for the dynamic pages of my site
at the end of the day it appears to be a full tree-optimised structure that works well SEO, There is a mod_rewrite rule that displays
mysite.com/folder/file
from
dynamic.php?filename

almostbob
Nearly a Senior Poster
3,280 posts since Jan 2009
Reputation Points: 585
Solved Threads: 398
Skill Endorsements: 7

That is a good lecture guys!
Thanks alot

Stefano Mtangoo
Senior Poster
3,731 posts since Jun 2007
Reputation Points: 462
Solved Threads: 396
Skill Endorsements: 0
Question Answered as of 4 Years Ago by buddylee17 and almostbob

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0688 seconds using 2.7MB