Exercise 5: Enabling the departure and price criteria on the Trip Search form

In this exercise, you will modify the Trip Search Results page to add the criteria needed for the departure and price query.

To enable the departure and price criteria:

  1. Open the gettrips.cfc file.
  2. In the getTripsFromForm method, position the pointer before the cfquery code block.
  3. To build the departureDate WHERE subclause, enter or copy and paste the code in the following table immediately before the cfquery code block:

    For this database

    Enter this code

    (Windows users) Microsoft Access database file

    <!--- Build subclause for departureDate --->
    <cfif Form.departureValue GT "">
    <cfif Form.departureOperator EQ "EQUALS">
    <cfset WhereClause = WhereClause & " and departureDate = " & CreateODBCDate(Form.departureValue)>
    <cfelseif Form.departureOperator EQ "AFTER">
    <cfset WhereClause = WhereClause & " and departureDate  > " & CreateODBCDate(Form.departureValue)>
    <cfelseif Form.departureOperator EQ "BEFORE">
    <cfset WhereClause = WhereClause & " and departureDate  <  " & CreateODBCDate(Form.departureValue)>
    </cfif>
    </cfif>
    

    (UNIX users) PointBase database file

    <!--- Build subclause for departureDate --->
    <cfif Form.departureValue GT "">
    <cfif Form.departureOperator EQ "EQUALS">
    <cfset WhereClause = WhereClause & " and departureDate = Date '"  &  Form.departureValue  &  "'"> 
    <cfelseif Form.departureOperator EQ "AFTER">
    <cfset WhereClause = WhereClause & " and departureDate > Date '"  & Form.departureValue  &  "'">
    <cfelseif Form.departureOperator EQ "BEFORE">
    <cfset WhereClause = WhereClause & " and departureDate < Date '"  &  Form.departureValue  &  "'">
    </cfif>
    </cfif>
    
  4. To build the price WHERE subclause, enter the following code after the code you entered in the previous step.
    <!--- Build subclause for price--->		
    <cfif Form.priceValue GT "">			
    	<cfif Form.priceOperator EQ "EQUALS">			
    		<cfset WhereClause = WhereClause & " and price = " & form.priceValue>
    	<cfelseif Form.priceOperator EQ "GREATER">
    		<cfset WhereClause = WhereClause & " and price > " & form.priceValue>
    	<cfelseif Form.priceOperator EQ "SMALLER">
    		<cfset WhereClause = WhereClause & " and price < " & form.priceValue>
    	</cfif>
    </cfif>
    
  5. Save the file.