Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2009
    Posts
    20

    Unanswered: Template For Articles Stored In DB - How do I get it out?

    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:
    Code:
    <?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!

  2. #2
    Join Date
    Dec 2009
    Posts
    20
    ...thanks for the reply of spam. Anyone else? Any ideas of how else to approach tihs?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •