Complicated situation. Please help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Complicated situation. Please help!

Post 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!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can't echo() code directly from a MySQL database - you need to look into using something like eval().

Mac
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

I love you Twig...

Twig...

I love you...
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply