Good morning everyone.
I have a rather detailed and intricate question (or maybe not... it seems that way to me however... hehe).
I'm in the middle of coding a fairly large website utilizing MySQL for it's database backend. The details of the site are largely unimportant to the question at hand... but I'm now in a position where this has driven me to inquire and perhaps glean some insight from those of you who are much more PHP savvy than I am.
What I've done is create a site that relies heavily on include files (with the naming convention 'filename.php'). A single HTML based index page is parsed with all the links being to differing include files that parse the link data to the relevant portions of the page.
Now what I've started doing is making a single include file for each link relevance. For example, a link calling the link variable "about us" would parse the index.php file with the aboutus.php include file to provide the content.
In most cases this works well... naturally I've taken this idea from many websites I've seen online.
However... it's when the particular link begins to require some rather larget amounts of PHP code that this gets a bit tedious... and hence my question.
In one situation, I have a link to "New Hires" which of course makes a call to the 'hrnewhire.php' include file. Naturally, I prefered to keep everything related to the approval of new hires in this include file... the list of new applicants, and when clicked on brings you to an approval page where changes can be made, and then submitted, etc. As a result... the 'hrnewhire.php' include file has gotten huge... well in excess of 15 pages of printed code if it were to be printed out in hard copy.
The way I have segregated the internal code in the 'hrnewhire.php' include file is by variables... and the entire file is split into sections using "if / else" statements based on those variables.
What I ended up having to do (just to keep my head straight at one point) was create include files for the 'hrnewhire.php' include file so that I could keep the different code snippets separate enough that I didn't confuse myself.
I'll create an example below:
<?php
// Define Variables //
$submit = $_GET[submit];
$view = $_GET[view];
// Create Page //
if($submit == "1") {
include('hrnewhire_submit.php');
// Which takes the new hire data and adds it to the database with a result message //
} else if($view == "1") {
include('hrnewhire_view.php');
// Which has a <a href=index.php?content=hrnewhire&submit=1>Submit New Hire Data</a> link //
} else {
// Create Initial Page Code //
....
....
....
<a href=index.php?content=hrnewhire&view=1>Click to Approve New Hire</a> // New hire link
}
?>
Naturally, what I end up having here in this example is 3 files instead of the single include file I wanted. Each include file has roughly 3 to 4 pages of code.
Now... my question here is twofold.
First... with you more proficient and experienced PHP developers out there... is this a good idea? I'd prefer, as I indicated, to have all the code relating to hrnewhires be in a single file... naturally after I've made sure that all the code works right then I can paste the relevant include files back into the main hrnewhire.php include to have a single file... but is that a good idea?
Secondly... if I ended up pasting everything back into a single large file... how does this affect bandwidth? Is it better to have a few smaller include files that get called, or a single large file that the server parses through to get the data?
I hope I've explained this well enough... if you need any further clarification or comments please let me know.