home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 April / APC443.iso / features / grpware / coldfus / coldfusi.exe / data1.cab / Documentation / snippets / cfquery.cfm < prev    next >
Encoding:
Text File  |  1998-10-08  |  1.9 KB  |  75 lines

  1. <!--- This example shows the use of CFQUERY --->
  2. <HTML>
  3. <HEAD>
  4.     <TITLE>CFQUERY Example</TITLE>
  5. </HEAD>
  6.  
  7. <BODY bgcolor=silver>
  8. <H3>CFQUERY Example</H3>
  9.  
  10. <!--- define startrow and maxrows to facilitate
  11. 'next N' style browsing --->
  12. <CFPARAM name="Startrow" default="1">
  13. <CFPARAM name="MAXROWS" default="10">
  14.  
  15. <!--- query database for information --->
  16. <CFQUERY NAME="GetParks" DATASOURCE="cfsnippets">
  17. SELECT      PARKNAME, REGION, STATE
  18. FROM         Parks 
  19. ORDER by ParkName, State
  20. </CFQUERY>
  21.  
  22. <!--- build HTML table to display query --->
  23. <TABLE cellpadding=1 cellspacing=1>
  24. <TR>
  25.     <TD colspan=2 bgcolor=f0f0f0>
  26.     <B><I>Park Name</I></B>
  27.     </TD>
  28.     <TD bgcolor=f0f0f0>
  29.     <B><I>Region</I></B>
  30.     </TD>
  31.     <TD bgcolor=f0f0f0>
  32.     <B><I>State</I></B>
  33.     </TD>
  34. </TR>
  35. <!--- Set a counter variable equal to startrow
  36. so that we can show visually where we are in the
  37. total recordset --->
  38. <CFPARAM name="Counter" Default="#StartRow#">
  39. <!--- Output the query and define the startrow and maxrows
  40. parameters --->
  41. <CFOUTPUT query="GetParks" StartRow="#startrow#" MAXROWS="#maxrows#">
  42. <TR>
  43.     <TD valign=top bgcolor=ffffed>
  44.     <B>#Counter#</B>
  45.     </TD>
  46.     <TD valign=top>
  47.     <FONT SIZE="-1">#ParkName#</FONT>
  48.     </TD>
  49.     <TD valign=top>
  50.     <FONT SIZE="-1">#Region#</FONT>
  51.     </TD>
  52.     <TD valign=top>
  53.     <FONT SIZE="-1">#State#</FONT>
  54.     </TD>
  55. </TR>
  56. <!--- increment the counter each row through the
  57. query output --->
  58. <CFSET #Counter# = #Counter# + 1>
  59. </CFOUTPUT>
  60.  
  61. <!--- If the total amount of records is less than or equal
  62. to the startrow + maxrows value, then offer a link to
  63. the same page, with the startrow value incremented by
  64. maxrows (in the case of this example, incremented by 10) --->
  65. <TR>
  66.     <TD colspan=4>
  67.     <CFIF (#StartRow# + #MAXROWS#) LTE #GetParks.RecordCount#>
  68.         <a href="cfquery.cfm?startrow=<CFOUTPUT>#Evaluate("#startrow#+#maxrows#")#</CFOUTPUT>">See next <CFOUTPUT>#MaxRows#</CFOUTPUT> rows</A>
  69.     </CFIF>
  70.     
  71.     </TD>
  72. </TR>
  73. </TABLE>
  74. </BODY>
  75. </HTML>