<HTML>
<TITLE>
 Taming the Net - Cold Fusion Sample Search Template
</TITLE>
<!---
     Filename:  Search.cfm
     Copyright: Sep. 21, 1997
                Michael L Gueterman 
                Easy Does It Technologies
--->
<BODY>
 <H1>
  Cold Fusion Sample Search Template
 </H1>
 <P>
  This CFML page will accept search values from
  the search.html page and will query the PARTSDBE
  database, specifically the PURCHDB.VENDORS table
  for tuples that match the search criteria.
 </P>
 <!---
   Notice that comments to be removed by the Cold Fusion server
   are enclosed by a tag with an exclamation mark followed by 
   three dashes whereas standard HTML comments use only two dashes.
   Likewise the ending comment tag uses three dashes in lieu of two.
 --->
 <!--- The following checks to see if a URL parameter named 'GO' was
       passed to this template.  This is a test to verify that the
       user didn't jump directly here without using the form.  Notice
       in the HTML FORM tag in the 'search.html' page the ?GO="Yes"
       value in the ACTION statement.  This passes the GO parameter with
       a value of YES to this page.  The value here is unimportant, the
       fact that the parameter was passed is the real test.
 --->
 <CFIF #ParameterExists(URL.GO)# is "No">
  <B>This form is only accessible via the 'search.html' form!</B>
 <CFELSE>
  <!--- Check to see if the user requested a Vendor Number search, and
        the value (if present) does not contain alpha characters.
  --->
  <CFIF #FORM.SEARCHTYPE# is "ID" and
        #LEN(TRIM(FORM.VALUE))# gt 0 and
        #IsNumeric(FORM.VALUE)# is "No">
   <B>Only numerals are allowed for a Vendor Number.</B>
  <CFELSE>
   <!--- Setup the SQL Query.  If no search value was specified then
         do not use a WHERE clause.  Otherwise check the value of
         the radio button to determine whether the information in
         the "value" field is meant to be used for the Vendor Number
         or Vendor Name search.
   --->
   <CFQUERY NAME="VendorSearch" DATASOURCE="PARTSDBE">
    Select * from PURCHDB.VENDORS
    <CFIF #LEN(TRIM(FORM.VALUE))# is not 0>
     WHERE
     <CFIF #FORM.SEARCHTYPE# is "ID">
      VENDORNUMBER = #FORM.VALUE#
     <CFELSE>
      <!--- For the Vendor Name search, utilize the 'LIKE'
            predicate.  ODBC uses a wildcard character of the
            percentsign (%) to match zero or more characters.
            For example, to search for all Vendor Names beginning
            with the letter 'S', the value entered would be 'S%'
            (without the quotes).
      --->
      VENDORNAME LIKE '#FORM.VALUE#'
     </CFIF>
    </CFIF>
   </CFQUERY>
   <!--- If the search didn't locate any matching tuples,
         tell the user so.
   --->
   <CFIF #VendorSearch.RecordCount# is 0>
    <HR>
    No tuples matched your selection criteria.
   <!--- The CFOUTPUT statement will repeat once for each row
         returned by the named query.  The HTML 'PRE' tag specifies
         that the browser is not to reformat the output in any way.
   --->
   <CFELSE>
    <CFOUTPUT QUERY="VendorSearch">
     <!--- Place a thin horizontal rule between each vendor
           that is returned by the query.
     --->
     <HR>
     <PRE>
      Vendor Number: #VendorSearch.VendorNumber#
      Vendor Name:   #VendorSearch.VendorName#
      Contact:       #VendorSearch.ContactName#
      Phone:         #VendorSearch.PhoneNumber#
      Address:       #VendorSearch.VendorStreet#
      City:          #VendorSearch.VendorCity#
      State:         #VendorSearch.VendorState#
      Zip:           #VendorSearch.VendorZipCode#
      Remarks:       #VendorSearch.VendorRemarks# 

     </PRE>
    </CFOUTPUT>
   </CFIF>
  </CFIF>
 </CFIF> 
 <!--- Place a thick horizontal rule following any information that 
       has been written by the above, and provide a hyperlink back
       to the search form.
 --->
 <HR SIZE=5>
  Return to <A HREF="search.html">Search Form</A>
</BODY>
</HTML>