I have a template for my pages stored in DreamWeaver. The template uses a mixture of PHP, HTML, and Javascript. I also am creating articles, and each article has its own page created when the article is created (ex: mysite.com/users/exampleuser/2010/03/17/example-article-title.php) so that each article can be indexed by search engines.
In order to change the template of all articles without having to physically change each article, I have the template stored in a DB. Each article's code looks like this:
<?php
require_once($_SERVER["DOCUMENT_ROOT"] . "/includes/db.php");
$sql = "SELECT Above_Content, Below_Content FROM templates WHERE ID = '1'";
$query = mysql_query($sql);
if ($row = mysql_fetch_assoc($query)) {
echo eval("?>".$row['Above_Content']);
//INSERT CONTENT HERE
$sql = "SELECT article_title, article_intro, article_content, author_id, creation_date, last_modified_date FROM articles WHERE article_id = '234'";
$query = mysql_query($sql);
if ($row = mysql_fetch_assoc($query)) { ?>
<div id="display_article">
<h1> <?php echo $row['article_title']; ?> </h1>
<p><?php echo $row['article_content']; ?></p>
</div>
<?php
}
$sql = "SELECT Above_Content, Below_Content FROM templates WHERE ID = '1'";
$query = mysql_query($sql);
if ($row = mysql_fetch_assoc($query)) {
echo eval("?>".$row['Below_Content']);
}
}
?>
Note the use of echo eval() to pull the template from the DB. Is there a better way to do this? I'm having a problem - the entire page (headers and below) are all being displayed "pushed down" from where they should be, as well as my Suckerfish drop-down menu won't work correctly - please note these errors are non-existent on the "real" template. Perhaps my javascript and other things aren't being evaluated properly? What other way can I approach this?
Thanks in advance!