User Guide

86 Chapter 7: Lesson 3: Creating a Main Application Page
Enhancing the look of the search results and detail pages
The Trip Maintenance search now provides a useful drill-down mechanism for locating trips.
While this application is functionally sound, the appearance of the dates and dollar amounts
could be improved.
ColdFusion provides several functions to improve the application appearance. The
DateFormat
and
DollarFormat functions format dates and currency variables.
Another part of the application that could be improved is the Trip Search Results table. In a large
list, it is sometimes difficult to correctly read the contents of a row in the middle of the table
because it is sandwiched between two other rows. To avoid mistakes in reading the table, it would
be helpful to alternate the background color of each row in the table.
The HTML table row
<tr> tag has a bgcolor attribute to change the background color for a
given row. To highlight every other row, the background color could be changed alternatively to
yellow or white. To change the background color for each row, you must determine whether the
row is an odd or even row. Therefore, you must obtain the sequence number of the current row
and test if it is evenly divisible by 2.
As described in Chapter 2, “CFML Basics,” on page 15, ColdFusion offers a modulus function
(
MOD) that returns the remainder (modulus) after a number is divided by a divisor; for example,10
MOD 3
is 1.
If the
MOD function returns a value greater than 0, a cfif test of its result evaluates to True. If the
MOD function returns 0, the cfif check evaluates to False.
The following example uses the
MOD function to alternate the background color of table rows:
<cfoutput query="tripResult">
<cfif CurrentRow Mod 2>
<cfset BackColor="White">
<cfelse>
<cfset BackColor="Yellow">
</cfif>
<tr bgcolor= "#BackColor#">
Notice that the MOD function uses a variable called CurrentRow. Notice also that CurrentRow is
not defined anywhere in tripsearchresult.cfm. The
CurrentRow variable is one of a few variables
that ColdFusion automatically exposes that provide information about the query. These
variables
are often called query variables.
Query variables
In addition to using the
cfquery tag to return data from a ColdFusion data source, you also can
use it to return information about a query. To do this, the
cfquery tag creates a query object,
providing information in query variables as described in the following table:
Variable Name Description
query_name.recordCount The number of records returned by the query.
query_name.currentRow The current row of the query being processed by cfoutput.
query_name.columnList A comma-delimited list of the query columns.