Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble displaying variables

Status
Not open for further replies.

danielleDee

Programmer
Jul 29, 2004
5
ZA
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

 
Sorry, I don't understand what you mean by
when I print FIELD1 within FIELD2

The code looks fine, assuming that the $display array contains what you expect.
 
are you saying you have this entire block:

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

in FIELD2 in a database? I've never seen php utilized in this manner. If you're then printing this field, php will echo $Field2, but the "code" in field 2 won't be evaluated, as it's interpreted as text.

A better method would be to store FIELD1 in a database, then do the following:

[tt]
<?php
while ($display = mysql_fetch_array($data)) {
echo '<table width="100%" height="200px"><tr>';
echo '<td>' . $display["FIELD1"] . '</td>';
echo '<td>&nbsp</td>';
echo '</tr></table>';
}
?>
[/tt]

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
oh...
I see now. cLFlaVA has the right answer.
There might be some more considerations here, especially naming database columns. FIELD1 really doesn't say anything descriptive about the content of the column.

If you want to evaluate the content of a variable as PHP code you can use the eval() function:
 
Hi

The reason the table html is stored in a database field is because the table structure must be editable in our content management system. The only glitch is the variable included in the table does not display.
 
You could eval() the PHP (i think that's the function) or you could write the php block to a temp file and then either include() or require() it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top