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 the Microsoft Internet Information Server. </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:
The following table gives a listing of default variables. These are environment variables for CGI applications and HTTP variables for IDC applications.
Variable | Meaning |
---|---|
ALL_HTTP | All HTTP headers that were not already parsed into one of the listed variables. These variables are of the form HTTP_<header field name>, for example:
HTTP_ACCEPT: */*, q=0.300, audio/x-aiff, audio/basic, image/jpeg, image/gif, text/plain, text/html HTTP_USER_AGENT: Microsoft Internet Explorer/0.1 (Win32) HTTP_REFERER: http://webserver/samples/dbsamp/dbsamp3.htm HTTP_CONTENT_TYPE: application/x-www-form-urlencoded HTTP_CONTENT_LENGTH: 10 |
AUTH_TYPE | The type of authorization in use. If the user name has been authenticated by the server, this will contain Basic. Otherwise, it will not be present. |
CONTENT_LENGTH | The number of bytes that the script can expect to receive from the client. |
CONTENT_TYPE | The content type of the information supplied in the body of a POST request. |
GATEWAY_INTERFACE | The revision of the CGI (Common Gateway Interface) specification with which this server complies. |
HTTP_ACCEPT | Special-case HTTP header. Values of the Accept: fields are concatenated, separated by a comma (,); for example, if the following lines are part of the HTTP header:
accept: */*; q=0.1 accept: text/html accept: image/jpeg then the HTTP_ACCEPT variable will have a value of: */*; q=0.1, text/html, image/jpeg |
LOGON_USER | The user’s Windows NT account. |
PATH_INFO | Additional path information, as given by the client. This comprises the trailing part of the URL after the script name but before the query string (if any). |
PATH_TRANSLATED | The value of PATH_INFO, but with any virtual path name expanded into a directory specification. |
QUERY_STRING | The information that follows the question mark (?) in the URL that referenced this script. |
REMOTE_ADDR | The IP address of the client. |
REMOTE_HOST | The hostname of the client. |
REMOTE_USER | The user name supplied by the client and authenticated by the server. |
REQUEST_METHOD | The HTTP request method. |
SCRIPT_NAME | The name of the script program being executed. |
SERVER_NAME | The server’s hostname (or IP address) as it should appear in self-referencing URLs. |
SERVER_PORT | The TCP/IP port on which the request was received. |
SERVER_PORT_SECURE | The value of 0 or 1. The value 1 indicates the request is on the encrypted port. |
SERVER_PROTOCOL | The name and version of the information-retrieval protocol relating to this request, usually HTTP/1.0. |
SERVER_SOFTWARE | The name and version of the Web server under which the Internet Server Extension is running. |
URL | The URL of the request. |