I currently have a very simple page, with some more complicated backend. I\'ve always done this the same way, but I feel it\'s not right. But I haven\'t come up with much us
Methinks that you are looking for templates.
Though you almost nailed it, you are mixing matters a little. Just separate your "design parts" from "code parts". Don't make header to do the job of the actual code and everything become as clear as a fresh water
Let me suggest you the following setup:
A site contains of
the main idea is to make PHP script do no output until all data got ready - thus you will get an instant solution of your page title problem. Moreover (think about it):
Once php script done with data preparations, it calls for the the main site timplate, which, in turn, will include the actual page template.
Thus you will get exactly what you're asking for - the website dynamic enough that it can have easily editable pages, but also be easily editable is a big part of it needs editing - and many more other benefits.
Template I am talking about is a typical PHP script, however, consists mostly of pure HTML, with some PHP code only to display dynamically generated data.
Here you go with some basic yet working example
the page:
//include our settings, connect to database etc.
include dirname($_SERVER['DOCUMENT_ROOT']).'/cfg/settings.php';
//getting required data
$DATA=dbgetarr("SELECT * FROM links");
// setting title for using in the main template
$pagetitle = "Links to friend sites";
//etc
//set page template filename
$tpl = "links.tpl.php";
//and then finally call a template:
include "main.tpl.php";
?>
where main.tpl.php
is your main site template, including common parts, like header, footer, menu etc:
My site. =$pagetitle?>
include $tpl ?>
and links.tpl.php
is the actual page template:
=$pagetitle?>
foreach($DATA as $row): ?>
- =$row['name']?>
endforeach ?>