Page 1 of 1

Trouble displaying variables

Posted: Mon Aug 09, 2004 9:28 am
by DanielleDee
Hi

I have the following code stored in FIELD2 in a database (mySQL):

<table width="100%" height="200px">
<tr>
<td><?php echo($display["FIELD1"]); ?></td>
<td>&nbsp</td>
</tr>
</table>

In my script I have the following code:

<?php
while ($display = mysql_fetch_array($data)) {
$FIELD1=$display["FIELD1"];
$FIELD2=$display["FIELD2"];

echo $FIELD2;
}?>

When I print $FIELD1 individually it displays correctly, but when I print FIELD1 within FIELD2, FIELD2 displays correctly but $FIELD1 does not execute. What am I doing wrong?

Thnx

Posted: Mon Aug 09, 2004 11:00 am
by feyd
check into [php_man]eval[/php_man]() or templates. Personally, I'd go the templates route. The problem with what you have now, is the content of the string $FIELD2 isn't evaluated, because it's considered pre-rendered text by that point.

Posted: Sun Aug 15, 2004 3:52 pm
by DanielleDee
Hi

I have adjusted the code in the database (field name = TEXT) as follows:
<table width='100%' border='0'><tr><td width='298' height='200' align='center' valign='top' unselectable='ON'><img src='../photos/$IMAGE'></td>
<td width='244' align='left' valign='top'>text</td>
</tr>
</table>
I've added the following code to the main page:

Code: Select all

<?php
eval("\$TEXT = "$TEXT";");
echo $TEXT. "\n";
?>
Now I get the error:
Parse error: parse error, unexpected '.' in ../test.php(18) : eval()'d code on line 7

test.php(18) is the eval() code line, but there is no '.' in the evaluated code?

Thanks

?>[/quote]

Posted: Sun Aug 15, 2004 10:56 pm
by feyd
I don't see a point in trying to set a variable to itself in that manner..

try something like this:

Code: Select all

&lt;table width="100%" height="200px"&gt;
&lt;tr&gt;
&lt;td&gt;&#123;S_DATA&#125;&lt;/td&gt;
&lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

Code: Select all

<?php
while ($display = mysql_fetch_array($data)) {
$FIELD1=$display["FIELD1"];
$FIELD2=$display["FIELD2"];
echo str_replace('{S_DATA}',$FIELD1,$FIELD2);
}?>