Web Server Variables . . Variable Expressions . . Variable Processing Functions . . Related Topics . . Home


Using Variables and Variable Expressions in AppPages

Variable names are case-sensitive, begin with $, and consist of alphanumeric and underscore characters, with a maximum of 80 characters. You can create user-defined variables and assign default values to them by setting them using the NAME attribute of the MIVAR tag within an AppPage. You can override default values for existing user-defined variables in an MIVAR tag, an HTML form, or a URL that invokes an AppPage. In addition, you can access Web server environment variables and Universal Web Connect system variables, set by the MISQL tag.

Displaying Web Server Environment Variables

You can access Web server environment variables within AppPages in the same way that you access other variables. The following display_var AppPage displays the value of the HTTP_USER_AGENT Web server environment variable.

  <HTML>
  <HEAD>
  <TITLE>Display a Variable</TITLE>
  </HEAD>
  <BODY>
  <HR>The value of the HTTP_USER_AGENT environment variable is
  <?MIVAR>$HTTP_USER_AGENT<?/MIVAR><HR>
  </BODY>
  </HTML>

The following is sample HTML generated when this tag is processed:

  <HTML>
  <HEAD>
  <TITLE>Display a Variable</TITLE>
  </HEAD>
  <BODY>
  <HR>The value of the HTTP_USER_AGENT environment variable is
  Mozilla/2.0 (WinNT;I)<HR>
  </BODY>
  </HTML>

Using Variable Processing Functions to Create Variable Expressions

Variable processing functions enable calculations to be performed using variables that are passed into an AppPage, generated within the AppPage, or returned from the database.

Variables are identified by $ followed by alphanumeric and underscore characters. Variable expressions start with $ followed by the expression within parentheses:

$(expression)

For example, the following variable expression returns the sum of three variables:

$(+,$var1,$var2,$var3)

Variable expressions can contain other variable expressions, for example:

$(TRIM,$(LOWER,$string))

Like variables, variable expressions in AppPages are only interpreted within MISQL, MIVAR, MIERROR, and user dynamic tags, and within the COND attribute of the MIBLOCK tag.

Variable Processing Functions

Click for a complete list of variable processing functions.

Arithmetic functions accept either decimal or integer arguments and perform all calculations in decimal arithmetic. Arithmetic functions that allow more than two arguments allow a maximum of 10.

Spaces are significant in the evaluation of variable expressions. For example, the variable expression $(EQ,$var1,$var2) is not equivalent to $(EQ, $var1,$var2) because the latter expression has a space before the string $var1.

The following sections show a variety of uses for variable processing functions to create simple and complex variable expressions.

Using Arithmetic Functions in Variable Expressions

The following varexp1 AppPage is an example of variable processing within an MIVAR tag:

  <HTML>
  <HEAD><TITLE>Adding Two Variables</TITLE></HEAD>
  <BODY>
  <?MIVAR NAME=NUMA>10<?/MIVAR>
  <?MIVAR NAME=NUMB>20<?/MIVAR>
  <?MIVAR><B>The sum of $NUMA and $NUMB is</B> $(+,$NUMA,$NUMB).
  <?/MIVAR>
  </BODY>
  </HTML>

The following is sample output returned to the client:

  <HTML>
  <HEAD><TITLE>Adding Two Variables</TITLE></HEAD>
  <BODY>
  <B>The sum of 10 and 20 is</B> 30.
  </BODY>
  </HTML>

The following is sample Web browser output.

Using String Functions to Process HTML Forms

Use the URLDECODE, POSITION, SUBSTRING, and REPLACE variable processing functions to parse a QUERY_STRING passed in an HTML form.

In the following example, the columns of the employees table are displayed as a check box list. The user is to check one or more columns of the employees table to be retrieved and then submit the form.

The form is posted to the same table_prog AppPage. On the second call to the AppPage, the SQL statement that retrieves the checked columns of the employees table is built. First, the URLDECODE function decodes the QUERY_STRING. Then the POSITION and SUBSTRING functions place commas between the selected columns to build the select statement. Finally, the REPLACE function is used to replace the commas separating items in the QUERY_STRING with TH tags to create an HTML table row. The output is displayed in an HTML table.

  <HTML>
  <HEAD><TITLE> Select from Table</TITLE></HEAD>
  <BODY>
  <!--- Show columns of employees table in a form --->
  <!--- with multi-value check box. Turn checked  --->
  <!--- columns into a comma-separated list.      --->
  <?MIVAR NAME=$column_headers> <?/MIVAR>
  <HR>
  <STRONG>Select Columns from Employees Table</STRONG><BR>
  <?MIVAR><FORM METHOD=GET ACTION="$WEB_HOME"><?/MIVAR>
  <INPUT TYPE=HIDDEN NAME=MIval VALUE="table_prog">
  <?MISQL SQL="select a.colname, colno from
    syscolumns a, systables b 
    where a.tabid = b.tabid and b.tabname = 'employees'
    order by colno;">
    <INPUT TYPE=CHECKBOX NAME=column_list VALUE="$1">$1<?/MISQL>
  <INPUT TYPE=SUBMIT VALUE="Get Rows"><HR>
  </FORM>
  <!--- On the second time through the form,     --->
  <!--- retrieve the selected columns from the   --->
  <!--- database, display in table format.       --->
  <?MIVAR NAME=$qstr>$(URLDECODE,$QUERY_STRING)<?/MIVAR>
  <?MIVAR NAME=$pos>$(POSITION,$qstr,"column_list=")<?/MIVAR>
  <?MIBLOCK COND="$(>,$pos,0)">
    <?MIVAR NAME=$column_list>$(SUBSTR,$qstr,$(+,$pos,12))<?/MIVAR>
    <?MIVAR NAME=$select_list>$(REPLACE,$column_list,"&column_list=",",")<?/MIVAR>
    <?MIVAR NAME=$column_headers>$(REPLACE,$select_list,",",</TH><TH>)<?/MIVAR>
     <TABLE BORDER>
     <TR><TH><?MIVAR>$column_headers<?/MIVAR></TH></TR>
     <?MISQL SQL="select $select_list from employees order by 1;">
	    <TR>{<TD>$*</TD>}</TR>
     <?/MISQL> 
   </TABLE>     
  <?/MIBLOCK>    
  </BODY>
  </HTML>

The following is sample Web browser output.

Related Topics

Using AppPage Tags
MIVAR


Top of Page . . Web Server Variables . . Variable Processing Functions . . Home