home *** CD-ROM | disk | FTP | other *** search
- <!--- This example shows the use of CFQUERY --->
- <HTML>
- <HEAD>
- <TITLE>CFQUERY Example</TITLE>
- </HEAD>
-
- <BODY bgcolor=silver>
- <H3>CFQUERY Example</H3>
-
- <!--- define startrow and maxrows to facilitate
- 'next N' style browsing --->
- <CFPARAM name="Startrow" default="1">
- <CFPARAM name="MAXROWS" default="10">
-
- <!--- query database for information --->
- <CFQUERY NAME="GetParks" DATASOURCE="cfsnippets">
- SELECT PARKNAME, REGION, STATE
- FROM Parks
- ORDER by ParkName, State
- </CFQUERY>
-
- <!--- build HTML table to display query --->
- <TABLE cellpadding=1 cellspacing=1>
- <TR>
- <TD colspan=2 bgcolor=f0f0f0>
- <B><I>Park Name</I></B>
- </TD>
- <TD bgcolor=f0f0f0>
- <B><I>Region</I></B>
- </TD>
- <TD bgcolor=f0f0f0>
- <B><I>State</I></B>
- </TD>
- </TR>
- <!--- Set a counter variable equal to startrow
- so that we can show visually where we are in the
- total recordset --->
- <CFPARAM name="Counter" Default="#StartRow#">
- <!--- Output the query and define the startrow and maxrows
- parameters --->
- <CFOUTPUT query="GetParks" StartRow="#startrow#" MAXROWS="#maxrows#">
- <TR>
- <TD valign=top bgcolor=ffffed>
- <B>#Counter#</B>
- </TD>
- <TD valign=top>
- <FONT SIZE="-1">#ParkName#</FONT>
- </TD>
- <TD valign=top>
- <FONT SIZE="-1">#Region#</FONT>
- </TD>
- <TD valign=top>
- <FONT SIZE="-1">#State#</FONT>
- </TD>
- </TR>
- <!--- increment the counter each row through the
- query output --->
- <CFSET #Counter# = #Counter# + 1>
- </CFOUTPUT>
-
- <!--- If the total amount of records is less than or equal
- to the startrow + maxrows value, then offer a link to
- the same page, with the startrow value incremented by
- maxrows (in the case of this example, incremented by 10) --->
- <TR>
- <TD colspan=4>
- <CFIF (#StartRow# + #MAXROWS#) LTE #GetParks.RecordCount#>
- <a href="cfquery.cfm?startrow=<CFOUTPUT>#Evaluate("#startrow#+#maxrows#")#</CFOUTPUT>">See next <CFOUTPUT>#MaxRows#</CFOUTPUT> rows</A>
- </CFIF>
-
- </TD>
- </TR>
- </TABLE>
- </BODY>
- </HTML>