Page 1 of 1

Complicated situation. Please help!

Posted: Thu Nov 28, 2002 10:11 am
by Jim
I'm creating a news system with editable templates, and I'm storing this template information on the MySQL DB.

The template includes variables in it such as $news, $date, $poster, etc.

In the script, I define these variables, and then echo $template. Problem is, when I call the template, the variables don't turn into their definitions. They just stick around as $news, $poster, etc.

For an example of this, visit http://www.empiregaming.net/news_prog/s ... m_news.php

That is what happens when I call $template.

This is the code in the template field in my table:

Code: Select all

<table cellpadding=3 cellspacing=0 border=0 class='body'><tr><td>$headline</td></tr><tr><td>$news</td></tr><tr><td>Posted by: $poster</td></tr></table>

This is the code on my page when I try to call that information.

Code: Select all

<?
include("config.php");
	
$sql = "select * from AOM_news where id = '1'";
$query = mysql_query($sql);

	if(!$query) {
		echo mysql_error();
		}
		
	if($query) {
		while ($data = mysql_fetch_assoc($query)) {
		
			$poster = $dataї'posted_by'];
			$headline = $dataї'headline'];
			$news = $dataї'news'];
			$template = $dataї'template'];
			
			echo $template;			
				} 
		
		}
		
		
?>
Now, I see what's happening. Those variables in $template are being put into the array as text, and are therefore not being defined. The question is, how do I define this?

Thanks for any help!

Posted: Thu Nov 28, 2002 10:25 am
by twigletmac
You can't echo() code directly from a MySQL database - you need to look into using something like eval().

Mac

Posted: Thu Nov 28, 2002 10:31 am
by Jim
I love you Twig...

Twig...

I love you...

Posted: Thu Nov 28, 2002 10:34 am
by twigletmac
I was cheating a bit since someone was trying to do this yesterday:
viewtopic.php?t=4654

I would've guessed at using that function but that thread confirmed it.

Mac