If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Template For Articles Stored In DB - How do I get it out?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-17-10, 15:55
tlshaheen tlshaheen is offline
Registered User
 
Join Date: Dec 2009
Posts: 20
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!
Reply With Quote
  #2 (permalink)  
Old 03-17-10, 23:52
tlshaheen tlshaheen is offline
Registered User
 
Join Date: Dec 2009
Posts: 20
...thanks for the reply of spam. Anyone else? Any ideas of how else to approach tihs?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On