4.5 RECORD Tag

    The RECORD tag is the mechanism by which a single block of RES-Reach code can be applied to a list of variable values or database records.

    Syntax for use within <DATA> tags:

        <RECORD>
            HTML statements to be included for each record in the data set.
        </RECORD>
    

    Syntax for use with multi-valued form variables:

        <RECORD NAME="Fld_Name">
            HTML statements to be included for each of the form variable values.
        </RECORD>
    

    Syntax for use with strings being tokenized:

        <RECORD NAME="Token_Name" TOKENIZE="String_to_be_tokenized" DELIM="String_Delimiter" > 
            HTML statements to be included for each token in the TOKENIZE string.
        </RECORD>
    

    where

    Fld_Name is the name of a multiple-valued field in an HTML input form;

    Token_Name is the name of the private variable to which the current token is assigned;

    String_to_be_tokenized is the string which is to be parsed or tokenized; and

    String_Delimiter is the delimiter string to use to parse the String_to_be_tokenized. Comparisons to this delimiter are case-sensitive.

    Do not use any of these elements when referencing record sets retrieved by a DATA tag.

    RECORD tags without the name property refer to the most recently opened DATA tag and only apply within that DATA tag. HTML code can be inserted between the RECORD tags, and will be repeated for every record within the set generated by the query. If the query returns no records, the record tags and what is between them are ignored. Within the RECORD tags, the value of the database fields are accessible as variables, enclosed in square brackets.

    Note: DATA tags containing an Action query (INSERT, UPDATE, or DELETE) are not compatible with RECORD tags or with database related variables such as {TotalRows}, and database field name variables. Use {RecNo} for zero/non-zero variables and COUNT(*) queries for accurate counts.

    RECORD tags with just the NAME element (Fld_Name) are used to iterate through multiple-valued input fields. For example, HTML SELECT tags or <INPUT TYPE="checkbox"...> multiple check boxes can return several values for the same variable based on user input.

    RECORD tags with the NAME, TOKENIZE and DELIM elements are used to parse a string to separate out tokens. The DELIM element may be a character or may be a string. If it is a string, then the occurrence of the entire string serves as the delimiter. Be aware that the NAME element is considered a private variable (in the _PRI group); any previous values it may have had before being used in the RECORD tag will be overwritten.

    Warning: If you are using file variables to modularize your code, be aware that RECORD start and end tags must always appear in the same file.

    Examples:

    Example 1: In the following example, Fld1 will have the three values (1, 3, 1) if this part of the form is not changed by the user:

    <SELECT MULTIPLE NAME="Fld1">
    <OPTION SELECTED VALUE="1"> Option A
    <OPTION VALUE="2"> Option B
    <OPTION SELECTED VALUE="3"> Option C
    <OPTION SELECTED VALUE="1"> Option D
    </SELECT>


    When RES-Reach receives these values, it can iterate through the three values (1, 3, 1) of the variable Fld1 with this syntax:

        <RECORD NAME="Fld1">
            Value number {RECNO} is {Fld1}<BR>
        </RECORD>
    

    The HTML sent to the Browser will be:

        Value number 1 is 1 <BR>
        Value number 2 is 3 <BR>
        Value number 3 is 1 <BR>
    

    Example 2: In the following example, a set of records is retrieved from a database and formatted into a table. The RECORD tags delimit what is included for each record if there is at least one record. The first record is preceded by a heading and the table header codes. For each record, there is a table row. If at least one record was retrieved, the table end tag is included. If no records were retrieved by the query, a different message is displayed.


    
    <DATA SQL="SELECT * FROM PRODUCTS;", DATABASE="{DB}", CONNECT="dBase III", MODE="READONLY">
    <RECORD>
    <IF VARIABLE="{RecNo}" OPERATOR="EQ" COMPARISON="1">
    <H1>Items retrieved</H1>
    <TABLE BORDER>
    <TR><TH>Item</TH><TH>Description</TH><TH>Cost per unit</TH></TR>
    </IF>
    <TR><TH> {[ITEM_ID]}</TH><TH>{[DESCRIPT]}</TH><TH>${[PER_UNIT]}</TH></TR>
    </RECORD>
    <IF VARIABLE="{TotalRows}" OPERATOR="NE" COMPARISON="0">
    </TABLE>
    <H4>A total of {TotalRows} items have been shown.</H4>
    </IF>
    <IF VARIABLE="{TotalRows}" OPERATOR="EQ" COMPARISON="0">
    <H1>No Items Match </H1>
    Select "Back" and re-enter the search, or send your request to our <A HREF="mailto:sales@myfirm.com">account manager</A>.
    </IF>
    </DATA>

    Example 3: In this example, a tokenizing record is used to parse cookies.


    
       <RECORD NAME="cookie" TOKENIZE="{_ENV.HTTP_COOKIE}" DELIM="; ">
          <RECORD NAME="crumb" TOKENIZE="{cookie}" DELIM="=">
             <IF VARIABLE="{RECNO}" OPERATOR="EQ" COMPARISON="1">
                <SET NAME="ThisVarName" VALUE="{crumb}">
             </IF>
             <IF VARIABLE="{RECNO}" OPERATOR="EQ" COMPARISON="2">
                <SET NAME="{ThisVarName}" VALUE="{crumb}">
             </IF>
          </RECORD>
       </RECORD>
    
    

    Example 4: This example shows how a (well-formed) file specification can be tokenized to separate out the directory and file name parts.


    
       <SET VARIABLE="DIR" VALUE="">
       <RECORD NAME="path" TOKENIZE="{NBT}" DELIM="/">
          <IF VARIABLE="{RECNO}" OPERATOR="EQ" COMPARISON="1">
             <SET VARIABLE="DIR" VALUE="{DIR}{path}">
          </IF>
          <IF VARIABLE="{RECNO}" OPERATOR="NE" COMPARISON="1">
        	 <SET VARIABLE="DIR" VALUE="{DIR}/{path}">
          </IF>
          <SET VARIABLE="FILE" VALUE="{path}">
       </RECORD>
       <RECORD NAME="dirname" TOKENIZE="{DIR}" DELIM="{PATH}">
          <IF VARIABLE="{RECNO}" OPERATOR="EQ" COMPARISON="1">
             <SET VARIABLE="FINALDIR" VALUE="{dirname}">
          </IF>
       </RECORD>
       Spec is "{NBT}"; <BR>
       Directory is {DIR}; <BR>
       Final Directory is {FINALDIR}; <BR>
       File is {FILE}
    
    

    Example 5: Finally, the tokenizing record can be used to create a simple DO loop.


    
       <RECORD NAME="DO" TOKENIZE="1,2,3,4,5,6,7,8,9,10" DELIM=",">
          {DO}<BR>
       </RECORD>