Approach 2. Embedding Smart Code in the HTML
This is the approach used by technologies such as PHP, ASP, or JSP, where you embed tags in the HTML document that the server interprets and executes, changing or generating HTML for you on the fly. For the purposes of this example I'll use PHP, but the approach using ASP or JSP is similar.
<table border="1" width="100%" id="table1" class="ms-classic4-main">
<!-- fpstyle: 7,011111100 -->
<p align="center">Sales details</td>
<td class="ms-classic4-top" align="right">
$result= mysql_query($strSql) or die(mysql_error());
while ($row = mysql_fetch_array($result))
<td class="ms-classic4-left"><?php echo($row['personname']);?></td>
<td class="ms-classic4-even"><?php echo($row['customername']);?></td>
<td class="ms-classic4-even"><?php echo($row['contractdescription']);
<td class="ms-classic4-even" align="right">
As you can see, the preceding code closely resembles the original HTML file, except that the hard-coded values have been removed in favor of code that generates the values from the database.
|Figure 3. PHP Report Output: Here's the report output generated by the PHP example. |
shows the output generated from the PHP page. Pretty good, huh?
The problem here is similar to that with the previous approach. You had to take the HTML off the designer, and amend it to "activate" it. This approach is less intrusive, as the developer needs only to add to the existing mockup HTML, rather than taking all the code and line-by-line putting it into out.println
statements as in the servlet examplebut the problem is, what happens when the HTML changes? You get an all-new document without your PHP tags in it, and have to start again. There are workarounds, such as making the designer work with your PHP when tweaking their design, but from experience this has led to more problems that it has solutions as WYSIWIG designer tools such as FrontPage can end up overwriting your code.