Click to See Complete Forum and Search --> : Most Efficient Way? for inlcudes


AaronChiles
04-18-2006, 03:18 PM
I am new to this forum and a post I found helped me out a lot, but I have some questions if I am doing everything right. First off, I am designing this website for a National Competition for FBLA (Future Business Leaders of America) it's a high school club.

The website which I am working on it http://nlc.naroni.com

And here is the code...I used php includes and page links to do the links, is this the most efficient way? What are some other options besides inline frames?

<!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>
<title>Welcome to Mooresville!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="images/style.css" />
<script type="text/javascript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<script type="text/javascript" src="images/flash.js">
</script>
</head>
<body bgcolor="#FFFFFF" style="background-image: url('images/bg_gold.jpg')" onload="MM_preloadImages('images/buttons/but_home_o.jpg','images/buttons/but_ourcommunity_o.jpg')">
<div align="center">
<table id="Table_01" width="617" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="7">
<img id="wtm_01" src="images/wtm_01.gif" width="491" height="52" alt="" /></td>
<td>
<img id="sail_top" src="images/sail_top.gif" width="36" height="52" alt="" /></td>
<td colspan="3">
<img id="wtm_03" src="images/wtm_03.gif" width="89" height="52" alt="" /></td>
<td>
<img src="images/spacer.gif" width="1" height="52" alt="" /></td>
</tr>
<tr>
<td colspan="11">
<img id="wtm_04" src="images/wtm_04.gif" width="616" height="13" alt="" /></td>
<td>
<img src="images/spacer.gif" width="1" height="13" alt="" /></td>
</tr>
<tr>
<td rowspan="8">
<img id="wtm_05" src="images/wtm_05.gif" width="13" height="521" alt="" /></td>
<td colspan="9" class="header">

<script type="text/javascript">

var flashban_top = new FlashObject("images/wtm_flash.swf", "ban_top", "590", "106", 6, "#5978b2");
flashban_top.write();

</script>

</td>
<td rowspan="8">
<img id="wtm_07" src="images/wtm_07.gif" width="13" height="521" alt="" /></td>
<td>
<img src="images/spacer.gif" width="1" height="106" alt="" /></td>
</tr>
<tr>
<td colspan="9">
<img id="wtm_08" src="images/wtm_08.gif" width="590" height="12" alt="" /></td>
<td>
<img src="images/spacer.gif" width="1" height="12" alt="" /></td>
</tr>
<tr>
<td rowspan="6">
<img id="wtm_09" src="images/wtm_09.gif" width="13" height="403" alt="" /></td>
<td rowspan="2" class="weather"><b>Current Conditions:</b> <?php
require_once("pxweather.class.php");
$w = new Weather($city = "KCLT", $force = true);
$w->load();
echo $w->getCurrent('temp.F');
?>

&ordm;F</td>
<td colspan="7">
<img id="wtm_11" src="images/wtm_11.gif" width="384" height="30" alt="" /></td>
<td>
<img src="images/spacer.gif" width="1" height="30" alt="" /></td>
</tr>
<tr>
<td rowspan="2">
<img id="wtm_12" src="images/wtm_12.gif" width="109" height="23" alt="" /></td>
<td class="date">
</td>
<td rowspan="5">
<img id="wtm_14" src="images/wtm_14.gif" width="13" height="373" alt="" /></td>
<td colspan="3" rowspan="3" class="navigation">
<p class="navigation">
<a href="index.php?page=home" title="home"><img src="images/buttons/but_home.jpg" border="0" style="width: 154px; height: 29px" /></a>
<a href="index.php?page=history" title="history"><img src="images/buttons/but_history.jpg" border="0" style="width: 154px; height: 29px" /></a>
<img src="images/buttons/but_ourcommunity.jpg" style="width: 154px; height: 29px" />
<img src="images/buttons/but_businessindustry.jpg" style="width: 154px; height: 29px" />
<img src="images/buttons/but_entertainment.jpg" style="width: 154px; height: 29px" />
<img src="images/buttons/but_futureoutlook.jpg" style="width: 154px; height: 29px" />
<img src="images/buttons/but_gallery.jpg" style="width: 154px; height: 29px" />
<img src="images/buttons/but_maps.jpg" style="width: 154px; height: 29px" />
<img src="images/buttons/but_citationdocumentation.jpg" style="width: 154px; height: 29px" />
<img src="images/buttons/but_contactus.jpg" style="width: 154px; height: 29px" /></p>
<p class="navigation">&nbsp;</p></td>
<td rowspan="5">
<img id="wtm_16" src="images/wtm_16.gif" width="1" height="373" alt="" /></td>
<td>
<img src="images/spacer.gif" width="1" height="17" alt="" /></td>
</tr>
<tr>
<td>
<img id="wtm_17" src="images/wtm_17.gif" width="193" height="6" alt="" /></td>
<td>
<img id="wtm_18" src="images/wtm_18.gif" width="107" height="6" alt="" /></td>
<td>
<img src="images/spacer.gif" width="1" height="6" alt="" /></td>
</tr>
<tr>
<td colspan="3" rowspan="2" class="content">

<div style="background-image: url(images/content.jpg); padding : 4px; width : 409x; height : 330px; overflow : auto; ">
<?php

switch($_GET['page']){
case "home":
include "home.php";
break;
case "maps":
include "maps.php";
break;
case "history":
include "history.php";
break;
default:
include "home.php";
}
?>
</div>

</td>
<td>
<img src="images/spacer.gif" width="1" height="335" alt="" /></td>
</tr>
<tr>
<td colspan="3" rowspan="2">
<img id="wtm_20" src="images/wtm_20.gif" width="154" height="15" alt="" /></td>
<td>
<img src="images/spacer.gif" width="1" height="4" alt="" /></td>
</tr>
<tr>
<td colspan="3">
<img id="wtm_21" src="images/wtm_21.gif" width="409" height="11" alt="" /></td>
<td>
<img src="images/spacer.gif" width="1" height="11" alt="" /></td>
</tr>
<tr>
<td colspan="11">
<img id="wtm_22" src="images/wtm_22.gif" width="616" height="13" alt="" /></td>
<td>
<img src="images/spacer.gif" width="1" height="13" alt="" /></td>
</tr>
<tr>
<td>
<img src="images/spacer.gif" width="13" height="1" alt="" /></td>
<td>
<img src="images/spacer.gif" width="13" height="1" alt="" /></td>
<td>
<img src="images/spacer.gif" width="193" height="1" alt="" /></td>
<td>
<img src="images/spacer.gif" width="109" height="1" alt="" /></td>
<td>
<img src="images/spacer.gif" width="107" height="1" alt="" /></td>
<td>
<img src="images/spacer.gif" width="13" height="1" alt="" /></td>
<td>
<img src="images/spacer.gif" width="43" height="1" alt="" /></td>
<td>
<img src="images/spacer.gif" width="36" height="1" alt="" /></td>
<td>
<img src="images/spacer.gif" width="75" height="1" alt="" /></td>
<td>
<img src="images/spacer.gif" width="1" height="1" alt="" /></td>
<td>
<img src="images/spacer.gif" width="13" height="1" alt="" /></td>
<td></td>
</tr>
</table>
</div>
</body>
</html>

bokeh
04-18-2006, 03:31 PM
here is the code... is this the most efficient way?No! Frames, tables and spacer gifs are all things out of the mid nineteen ninties that can and should be avoided in this day and age.

AaronChiles
04-18-2006, 03:35 PM
Yeah, I'm working on getting rid of all the spacer.gifs, but thats the way Photoshop exported it. Other than that I didn't know tables were bad, I mean I am using CSS for backgrounds, etc? But my main focus is the PHP in my code, is there an easier way to make it so it opens up in that <DIV>?

replica
04-18-2006, 05:30 PM
I like this style of including files by a GET variable. I've been using it for a while but I add a bit of error handling. As for efficiency; I think it's faster to use single quotes whenever possible in PHP so that it doesn't parse for escaped characters... other then that I can't think of much more to do to it.

switch( @$_GET['page'] )
{
case 'home':
includeFile( 'home.php' );
break;
case 'maps':
includeFile( 'maps.php' );
break;
case 'history':
includeFile( 'history.php' );
break;
default:
includeFile( 'home.php' );
}

function includeFile( $name )
{
if( ! file_exists( $name ) )
print "<div class='error_note'>File '{$name}' could not be found.</div>";
else
include( $name );
}

...something like that

AaronChiles
04-19-2006, 11:11 PM
Thanks it works like a charm, I can't get rid of the spacer.gif 's and the bottom table row unfortunately. I tried to export it to <div> style, but it can't center align it to the website.

bokeh
04-20-2006, 04:21 AM
I like this style of including files by a GET variable.Query strings are for transfering unique data from the client to the server and should not be used as a method for loading files. In my opinion it is a terrible way to code.

Sheldon
04-20-2006, 04:36 AM
I agree with Bokeh,

I find it is better (and it is better for searh engines) to include the static pages in to the dynamic page rather than to include the dynamic pages into the static.

so in this case rather than a switch including the content i would have indervidual pages including the headers

eg:
header.php

//breif example
<htm>
<head>
<title>Site name - <?php echo($title); ?></title>
</head>
<body>


footer.php

</body>
</html>



and for your pages do this
each page name.php

<?php

session_start();

$title = "pagename";

include("header.php");

?>
Page content

<?php

include("footer.php");
?>

cdwhalley.com
04-20-2006, 04:39 AM
...tables... are ... things out of the mid nineteen ninties that can and should be avoided in this day and age.

www.microsoft.com (http://www.microsoft.com) <- uses tables

bokeh
04-20-2006, 05:17 AM
www.microsoft.com (http://www.microsoft.com) <- uses tablesWhat is your point? Microsoft is certainly not a company I would use as an example of what is cutting edge. Microsoft's current web browser, Internet Explorer 6, doesn't even fully impliment the CSS1 standard introduced on 17 December 1996.

Tables in this context are used by people whose design abilities don't extend beyond the level of assembling Lego blocks and are used with little or no attention paided to accessibility.

AaronChiles
04-20-2006, 10:04 AM
My first intention was to use the header/footer.php includes and just have the main page, but I found it rather hard to split up my code to get the same layout and that style.

bokeh
04-20-2006, 10:18 AM
Well it's pretty simple really. Print your HTML source code and then take a pair of scissors and cut off the bit at the top that is common to all pages. Now do the same at the bottom making sure all elements that were opened in the head section are correspondingly closed in the foot section. You now have your three separate parts.

replica
04-20-2006, 11:45 AM
Query strings are for transfering unique data from the client to the server and should not be used as a method for loading files. In my opinion it is a terrible way to code.

I have run into a couple of problems with it. Main one was IIS not liking POST data being sent to default documents... I'm sure there's a better way to say it.
<form method="post" action="?page=login">
...
</form>

Apparently my IIS had a security patch and this just won't cut it. At least on my home machine. `index.php?page=login` still works though. And (I think) it's still very usable for keeping site contents nice and organized but I can see how people can dislike it.

bokeh
04-20-2006, 12:04 PM
I have run into a couple of problems with it. Main one was IIS not liking POST data being sent to default documents... I'm sure there's a better way to say it.Good reason to listen to me then. Apache has no such problem though and can accept POST data to URIs with query strings without any problem. Maybe this is yet another reason to support Apache over IIS.

cdwhalley.com
04-20-2006, 01:33 PM
What is your point?
My point was that you shouldn't tell him that tables are wrong and old-fashioned when, despite what is 'cutting edge' and what isn't, they are still used by a large number of sites on the internet for layout purposes, and designers are still making sites that use tables for layouts, and I think they still will be in the future.
Besides, the CSS needed to create the same precision in layouts as can be achieved with 'old fashioned' tables can be quite complicated, so for a beginner it is better to suggest that they use tables, and work on learning CSS.
But sites that use CSS for all the layout are the ultimate goal, despite the difficulty in achieving it.

bokeh
04-20-2006, 01:44 PM
My point was that you shouldn't tell him that tables are wrong and old-fashionedAnd my point is that using tables for document layout is for people who are either too stupid or too ignorant to lay their site out according to current web standards.

If someone is a beginner then they would not be poluted with tables layouts so encouraging or advocating such a thing is ridiculous.

When my 3 year old wants the window open I teach him how to do it properly, I don't supply him with a large hammer with which to do it because it might be "easier" for a "beginner" to understand.

cdwhalley.com
04-20-2006, 02:17 PM
But now you've just called our friend AaronChiles stupid and ignorant, when he is only a beginner.
When I was a beginner I used tables for layout, because thats what the book I was using told me about.
Finally, there must be an awful lot of broken windows about. Including around microsoft's offices, amazon.com's offices, ebay.com's offices....

bokeh
04-20-2006, 02:26 PM
I made no personal statement against anyone in particalar so please don't try to suggest otherwise.

What you recomend is babytalk. Many people teach their youngster that a dog is called a "woof woof" and a cow is called a "moo moo". The outcome is the children seem stupid and backwards compared to ones that were taught properly in the first place.

cdwhalley.com
04-20-2006, 02:43 PM
But that is appropriate for babies at the time! As long as they are not still saying that at the age of 10 then there is no problem with it. When you start designing websites you just learn HTML - not CSS, just HTML. With just HTML the only way for such layouts is with tables. So, until they learn CSS up to the standard that is need for complicated layouts, which is a bit more that just background-color, color, font-family, the best thing for them to use is tables. It is not helpful to just tell someone that tables are wrong and old-fashioned when the replacement for them is above their level. I think you would except a young child to call a cow a 'moo moo', because for their level it is acceptable, even though the correct term is a bovine. When they are older and have moved beyond that you can educate them. But, when they are using the word 'cow', they will still see adults refering to them as 'moo moos'.

AaronChiles
04-20-2006, 03:00 PM
Well I designed the site in Photoshop and exported it according the XHTML template. I tried exporting it by CSS or <DIV> but the CSS was all messed up, and the <DIV> tags did not center properly on the page since it was an absolute placement instead of a relative.

bokeh
04-20-2006, 03:00 PM
It is not helpful to just tell someone that tables are wrong.It is when it is true. The truth is to learn a basic HTML/CSS layout is far less complicated than a comparable tables layout. It also leads to files that are far smaller and that render far more quickly especially in browsers like Internet Explorer. And we haven't even started on the accessibility arguments yet.

fci
04-20-2006, 03:03 PM
I like this style of including files by a GET variable. I've been using it for a while but I add a bit of error handling. As for efficiency; I think it's faster to use single quotes whenever possible in PHP so that it doesn't parse for escaped characters... other then that I can't think of much more to do to it.

switch( @$_GET['page'] )
{
case 'home':
includeFile( 'home.php' );
break;
case 'maps':
includeFile( 'maps.php' );
break;
case 'history':
includeFile( 'history.php' );
break;
default:
includeFile( 'home.php' );
}

function includeFile( $name )
{
if( ! file_exists( $name ) )
print "<div class='error_note'>File '{$name}' could not be found.</div>";
else
include( $name );
}

...something like that


I do not recommend using a wrapper like that for an include.. (ok, it depends). one of the potential reasons to not use it is because of how it affects variable scope (which is why it depends, if losing scope is not an issue then there's no need to fret; functions and classes are global anyway).

here is a cleaned up version of your example since the approach can still be useful:
<?php
switch (@$_GET['page']) {
case 'home':
case 'maps':
case 'history':
include($_GET['page'].'.php');
break;
default:
include('home.php');
}
?>
for my case, I tend to use classes instead of switches. switches are less modular and can be redundant when taking an MVC approach.

AaronChiles
04-20-2006, 03:07 PM
You guys banter a lot, here is my latest code, I added some buttons on the side, I know it's not XHTML 1.0 Transitional Validated, I haven't went through and fixed all the errors yet. I can use the Convert to Layers function in Dreamweaver to get the <DIV> tags like you guys all want since "tables are old", but then I have placement issues, so how do I get it to center automatically on the page like the table does?

http://nlc.naroni.com/code.html

cdwhalley.com
04-20-2006, 03:15 PM
It is when it is true. The truth is to learn a basic HTML/CSS layout is far less complicated than a comparable tables layout. It also leads to files that are far smaller and that render far more quickly especially in browsers like Internet Explorer. And we haven't even started on the accessibility arguments yet.
Correct, correct and correct. But, that all happens afterwards - remember, I am talking about beginners. Beginners don't know CSS, especially not the advanced CSS needed to make layouts comparable to what can be achieved with tables in HTML.

bokeh
04-20-2006, 03:34 PM
Correct, correct and correct. But, that all happens afterwards - remember.We'll have to agree to differ on this. Beginner or not I am not going to recommend that anyone use inaccessible mark-up that is stuck in a timewarp.

cdwhalley.com
04-20-2006, 03:49 PM
Oh, I would always recommend anyone using tables to progress to CSS, just not to start with it.
Perhaps with starting with tables they will learn their strengths/weaknesses better.
But, yes, we shall agree to disagree. You raise some very good points.

Sheldon
04-20-2006, 04:13 PM
Why would you even bother to start with tables? If you start with CSS then your better off right from the start. And as CSS being to hard for a beginner?

Do a few tutorials on places like w3schools.com and the like and you will have no problems.



AndAaron Chiles, Your code has alot of extra crap in it.
To center the css layout with out seeing it, you could put it in a div like this

<div style="width: 800px;
margin: 0;
padding: 0;
text-align: center;
">
main content
</div>

bokeh
04-20-2006, 04:19 PM
Oh, I would always recommend anyone using tables to progress to CSS, just not to start with it.This is a joke really. This whole discussion would lead anyone reading to believe that you either use tables or CSS but that is not true. The reality is you either use CSS to style your document or you use CSS to style the tables contained in your document. Either way you need CSS.

cdwhalley.com
04-20-2006, 04:44 PM
You needn't use CSS at all, although it's not a good idea.
The reality is you either use CSS to style your document or you use CSS to style the tables contained in your document.
But this is what we were talking about all along...

AaronChiles
04-22-2006, 01:40 PM
So I'm on to the next step of the site, and that is a site search. How is that going to work out since they are are all includes? I need some serious help with this, any suggestions?

bokeh
04-22-2006, 02:41 PM
The easiest way for a "beginner" would be http://www.google.com/searchcode.html

NogDog
04-22-2006, 02:42 PM
OK, folks, there are more than enough of "tables vs. CSS" discussions in the CSS forum. Let's try to keep it to PHP here, please. If you feel a need to continue this off-topic discussion, please open up a new thread in an appropriate forum for that purpose.