Hi,
I have an HTML table stored in a MySQL table. Within the HTML, I want to pass a variable that is pulled out of another table. Here is a section of the content that is stored in the table:
<tr>
<td width="50%" height="21">
<p align="center"><font face="Arial" size="4">$m->business_name</font></td>
</tr>
I call the HTML table from MySQL using the following code:
$result = $db->query("SELECT html FROM offer_layout WHERE id='$id'");
$row = mysql_fetch_array($result);
$html = $row['html'];
To get the HTML table onto the web page, I do the following:
$mainContent = <<<EOD
$html
EOD;
Here is the problem - When the HTML table gets displayed, instead of seeing the business name and other business variables in the table, all I see are the variable names, such as "$m->business_name". How do I get the actual variable passed here?
I am storing the HTML table in a database table, as I have 4 different layouts that are used to either display on the web page, or to create the HTML table in an email that gets sent out.
Any advice?
- Joe
MySQL Question - Populating a variable inside of stored HTML
Moderator: General Moderators
-
JoefromPhilly
- Forum Newbie
- Posts: 8
- Joined: Sat May 31, 2008 3:36 pm
Re: MySQL Question - Populating a variable inside of stored
Eww...
Do not put PHP code in a database. It's a slippery slope and it ends at massive security holes.
You can use templating instead. Same basic idea as to what you have now, except instead of PHP variables you have unique little strings. For example,
Then a simple str_replace to substitute "%BUSINESS NAME%" for $m->business_name.
Do not put PHP code in a database. It's a slippery slope and it ends at massive security holes.
You can use templating instead. Same basic idea as to what you have now, except instead of PHP variables you have unique little strings. For example,
Code: Select all
<tr>
<td width="50%" height="21">
<p align="center"><font face="Arial" size="4">%BUSINESS NAME%</font></td>
</tr>