Including a page in database display

I have a text file that includes another file near the end of the article…


<p>Text...</p>
<?php require_once($BaseINC."/2B/inc/D/Content/Child/Bits/GZ/TopicLevels.php"); ?>
<p>More text...</p>

I want to put this article into a database table, but database queries don’t display PHP scripts, of course. I discovered that I could replace echo values - e.g. <php echo $BaseURL; ?> - with a simple $BaseURL, then use str_replace to replace it with an actual echo value in my display:


str_replace('$BaseURL', ''.$BaseURL.'', $Text);

But I can’t figure out how to insert an include in my database display. I thought it might be easiest if I first convert the include to an echo value…


$Content = str_replace('$TopicLevels', ''.$TopicLevels.'', $Content);

But how do I write the echo value? I’ve tried various combinations of single quotes, double quotes and back slashes. But I suspect I’m using the wrong approach to begin with.


 $TopicLevels = '.<?php require_once($BaseINC."/2B/inc/D/Content/Child/Bits/GZ/TopicLevels.php"); ?>.';
 $Content = str_replace('$TopicLevels', ''.$TopicLevels.'', $Content);

(I should explain that my include contains a variable ($BaseINC) to allow for different locations of includes 1) on my Mac laptop, 2) on a Windows machine and 3) online.)

Thanks.

$query = “SELECT * FROM db”;
$sql = mysql_query($query);
$row = mysql_fetch_array($sql);

$var1 = $row[content];
$var2 = $row[content2];

I am under the impression that what you are trying to achieve cannot be done.

Howeve if you add two more fields, $link and $var2 to the table then this may work:



   $query = "SELECT * FROM db";
   $sql = mysql_query($query);
   $row = mysql_fetch_array($sql);

   $var1 = $row[content];
   $var2 = ''; 
   if( ! empty( $row[link] ) )
   {
      $var2 = include $row[link];
   }   
   $var3 = $row[content2];

   $article = $var1 .$var2 .$var3;

   echo '<p>' .$article .'</p>';


You could also test for a TOKEN in $row[content] and if it exists then replace TOKEN with $row[link].

Thanks for the tips; I’ll check them out. (It’s amazing that MySQL databases aren’t more PHP friendly!)