HI,
I need to know how to display a variable from DB that has antoher variable in it: here is what i mean

($Description) is an variable that contain this html code:

<table height="688" width="500" border="0">
    <tbody>
        <tr>
            <td width="82%" height="20"><strong><font face="Arial">$Name</font></strong></td>
            <td height="20"><strong><font face="Arial">$Item_num</font></strong></td>
        </tr>
        <tr>
            <td colspan="2" height="380">&nbsp;</td>
        </tr>
        <tr valign="top" align="center">
            <td colspan="2" height="288"><img height="275" src="$Big_pic" width="327" border="0" alt="" /><br /><a onclick="self.close()" href=""><strong><font face="Arial">CLOSE WINDOW</font></strong></a> </td>
        </tr>
    </tbody>
</table>

Now my question is if you see closely there are more variable in this code and i want to display them but i only see $Name and not the original value so does any 1 kno how to make the php display the variable value instead of ($Name) Variable it self.

Recommended Answers

All 4 Replies

I'm pretty sure that all that you have to do is simply print / echo $Description variable.

Another thing that you have to do to replace all $Name and similar things in HTML code with their values is to embrace them with PHP marks <? and ?>.

I'm not quite sure whether it will be OK or not, but you may try it out...:

<table height="688" width="500" border="0">
<tbody>
<tr>
<td width="82%" height="20">
<strong>
<font face="Arial"><? $Name ?></font>
</strong>
</td>
<td height="20">
<strong>
<font face="Arial"><? $Item_num ?></font>
</strong>
</td>
</tr>
<tr>
<td colspan="2" height="380">&nbsp;</td>
</tr>
<tr valign="top" align="center">
<td colspan="2" height="288">
<img height="275" src="<? $Big_pic ?>" width="327" border="0" alt="" /><br />
<a onclick="self.close()" href=""><strong><font face="Arial">CLOSE WINDOW</font></strong></a>
</td>
</tr>
</tbody>
</table>

Of course, there is a limitation that surrounding has to be written as php document for this to have any effect, other wise you'll get just printed out variables with <? and ?> as a decoration...

Hi thx i think it works but i have another problem as i use a wysiwyg editor and when ever i put < or > it puts some html code for it so is there a php command that replaces that html command with the < or >.

Hi thx i think it works but i have another problem as i use a wysiwyg editor and when ever i put < or > it puts some html code for it so is there a php command that replaces that html command with the < or >.

You want to say that instead of "<" and ">" you're getting &gt and &lt signs, or something similar?

Well... you have to change entry in a DB for this to have effect...

If you can't do that, I'd recommend you to write some if's in your code to display thing that you want, and as fas as it goes for HTML part of $Description variable - leave it written... menaing - do not insert this into a DB table, just values for $Big_pic, $Name and so on... and extract those thins from DB and insert them inside "<?" and "?>" 'brackets'... it is much easier to solve, not to talk abot understanding the code... beleive me...

I found it
Instead of using the the if statement or making changes to db i used the replace statement:

$Description = str_replace('$Name', "$Name", $Description);
$Description = str_replace('$Item_num', "$Item_num", $Description);
$Description = str_replace('$Big_img', "$Big_pic", $Description);

I think these three replace statements do the same job faster...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.