HTML extension files contain a number of keywords that control how the output HTML document is constructed. These keywords are explained in the following sections.
The <%begindetail%>, <%enddetail%> keywords surround a section of the HTML extension file in which the data output from the database will be merged. Within the section, the column names delimited with <% and %> or <!--%%-->are used to mark the position of the returned data from the query. For example:
<%begindetail%>
<%au_lname%>: <%ytd_sales%>
<%enddetail%>
will list the columns au_lname and ytd_sales. Any column can be referred to in this way. Column names can also be referred to elsewhere in the HTML extension file.
Note If there are no records returned from the query, the <%begindetail%> section will be skipped. For each SQL statement that generates a result set (for example, SELECT), there should be a corresponding <%begindetail%> <%enddetail%> section in the .htx file.
HTML extension files can contain conditional logic with an if-then-else statement to control how the Web page is constructed. For example, one common usage is to insert a condition to display the results from the query on the first row within a <%begindetail%> section; but if there are no records returned by the query, to display the text "Sorry, no authors had YTD sales greater than" %idc.sales%. By using the <%if%> statement and a built-in variable called "CurrentRecord" you can tailor the output so that the error message is printed when no records are returned. Here is an example showing the use of the <%if%> statement.
<%begindetail%><%if CurrentRecord EQ 0 %>
Query results:
<B>Author YTD Sales<BR></B>
<%endif%>
<%au_lname%><%ytd_sales%>
<%enddetail%>
<P>
<%if CurrentRecord EQ 0 %>
<I><B>Sorry, no authors had YTD sales greater than </I><%idc.sales%>.</B>
<P>
<%else%>
<HR>
<I>
The Web page you see here was created by merging the results of the SQL query with the template file Sample.htx.
<P>
The merge was done by the Microsoft Internet Database Connector and the results were returned to this Web browser by Microsoft Internet Information Services.
</I>
<%endif%>
</BODY>
</HTML>
The general syntax is:
<%if condition %>
HTML text
[<%else%>
HTML text]
<%endif%>
Where condition is of the form:
value1 operator value2
and operator can be one of the following:
EQ | if value1 equals value2 |
LT | if value1 is less than value2 |
GT | if value1 is greater than value2 |
CONTAINS | if any part of value1 contains the string value2 |
The operands value1 and value2 can be column names, one of the built-in variables (CurrentRecord or MaxRecords, see below), an HTTP variable name (see following), or a constant. When used in an <%if%> statement, values are not delimited with <% and %>. For example, to do special processing on author name "Green," use the condition:
<%begindetail%>
<%if au_lname EQ "Green"%>
this guy is green!
<%endif%>
<%enddetail%>
The <%if%> statement can also be used to do special processing based on information from HTTP variables. For example, to format a page differently based on the type of client Web browser you could include the following in the HTML extension file.
<%if HTTP_USER_AGENT contains "Mozilla"%>
client supports advanced HTML features
<%else%>
client is <%HTTP_USER_AGENT%>
<%endif%>
The CurrentRecord built-in variable contains the number of times the <%begindetail%> section has been processed. The first time through the <%begindetail%> section, the value is zero. Subsequently, the value of CurrentRecord changes every time another record is fetched from the database.
The MaxRecords built-in variable contains the value of the MaxRecords field in the Internet Database Connector file. MaxRecords and CurrentRecord can only be used in <%if%> statements.
Parameters from Internet Database Connector files can be accessed in the HTML extension file by prefixing the name of the parameter with "idc" and a period. In Sample3.htx shown earlier, you could show the value of the parameter %sales% by including the line:
The value of the sales parameter is: <%idc.sales%>
Several variables in HTML extension files can give a lot of information about the environment and Web client connected to the server. In addition all headers sent by the client are available. To access them by using the Internet Database Connector you must convert them: