home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Documentation / snippets / cfquery.cfm < prev    next >
Encoding:
Text File  |  1999-04-12  |  1.8 KB  |  71 lines

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