Peter Theobold who frequents the list wrote this tag :))



------------------------------------------------------------

Just to thank everyone on this mailing list (and especially Justin Kidman
who helped me with this) I present for your dissecting pleasure:
CF_OUTPUTPG.cfm

I wrote this module both because I needed it and as an exercise in writing
my first custom tag.
It works the same as CFOUTPUT QUERY="queryname" with the added feature that
it PAGES long results one block per web page. It also returns all the
numbers you need to put a NEXT and PREV button on the bottom.

So, here it is, the source code and a sample test file that uses it:
(forgive me if Eudora messes up the indenting)

<!---
//  Module outputpg.cfm
//  Peter Theobald 8/10/2000
//  [EMAIL PROTECTED]
//  Easy output of query data in paged format
//
//  Usage:
//  <CF_OUTPUTPG query="queryname" {OPT} startrow=1 {OPT} maxrows=10 >
//  ... CFML that uses #queryname.column# ...
// </CF_OUTPUTPG>
//
//  Returns: outputpg.prevstart, outputpg.nextstart,
//       outputpg.numpages, outputpg.thispage
--->

<cfif ThisTag.ExecutionMode is "end">
  <cfparam name="attributes.startrow" default="1">
  <cfparam name="attributes.maxrows" default="10">
  <cfscript>
  rc = evaluate("caller.#attributes.query#.recordcount");
  // Why can't CF be zero based like any sane language?
  numpages = (rc-1)\attributes.maxrows +1;
  thispage = (attributes.startrow-1)\attributes.maxrows +1;
  prevstart = ((attributes.startrow-2)\attributes.maxrows)
        * attributes.maxrows +1;
  if (prevstart LT 0) prevstart = 1;
  nextstart = ((attributes.startrow+attributes.maxrows)\attributes.maxrows)
        *  attributes.maxrows +1;
  if (nextstart GT rc)
        nextstart = attributes.startrow;
  // Make these available to the caller:
  caller.outputpg.numpages = numpages;
  caller.outputpg.thispage = thispage;
  caller.outputpg.prevstart = prevstart;
  caller.outputpg.nextstart = nextstart;
  // put query in local scope to evaluate tag body
  scopeexp = "#attributes.query# = caller.#attributes.query#";
  evaluate(scopeexp);
  </cfscript>
  <cfoutput query="caller.#attributes.query#" startrow=#attributes.startrow#
        maxrows=#attributes.maxrows#>
  #Evaluate("""#ThisTag.GeneratedContent#""")#
  </cfoutput>
  <cfset ThisTag.GeneratedContent = "">
</cfif>

<!--- --- --- --- END OF FILE --- --- --- --->



<!---
// Testpg.cfm
// Peter Theobald 8/10/2000
// [EMAIL PROTECTED]
//
// This file is a simple example of using the CF_OUTPUTPG module
// Make sure outputpg.cfm is in the same directory or in your CustomTags
directory
--->

<!---
// replace this with your own favorite query
// make it 3 columns if you want to keep
// all the formatting the same as whats already below.
--->
<cfquery name="q_users" datasource="#MyDSN#">
        select UserName, UserType, Email
        from Users
</cfquery>

<html><body>

This is a test of custom tag CF_OUTPUTPG.<p>
<cfparam name="url.startrow" default="1">

<table border=1 width=50%><tr><td>User</td><td>Type</td><td>Email</td></tr>

<cf_outputpg query="q_users" startrow="#url.startrow#">
<tr><td>#UserName#</td><td>#UserType#</td><td>#Email#</td></tr>
</cf_outputpg>

</table>

<table border=0 width=50%>
<tr><cfoutput>
<td><a href="testpg.cfm?startrow=#outputpg.prevstart#">PREV PAGE</a></td>
<td align=center>Page #outputpg.thispage# of #outputpg.numpages#</td>
<td align=right><a href="testpg.cfm?startrow=#outputpg.nextstart#">NEXT
PAGE</a></td>
</cfoutput></tr></table>
</body></html>

<!--- --- --- --- END OF FILE --- --- --- --->


Further enhancements:
o       Add "calculate only" mode. If the 'query' argument is missing and
the 'numrecords' argument is present
        simply calculate all the numbers and return them. This will be
useful if the user wants to put the page number
        or NEXT and PREV buttons *before* the actual results display.
o       Accept 'group' and 'groupcasesensitive' arguments and pass them
through to the CFOUTPUT

---------------------------------------------------------------------------
Peter Theobald, Chief Technology Officer
LiquidStreaming http://www.liquidstreaming.com
[EMAIL PROTECTED]
Phone 1.212.545.1232 Fax 1.212.679.8032

----------------------------------------------------------------------------
--
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.

-----Original Message-----
From: Greenberg, Lisa [mailto:[EMAIL PROTECTED]]
Sent: Monday, August 28, 2000 7:28 PM
To: cftalk (E-mail)
Subject: How to display data in blocks of 10 with a "Next" Feature


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C01147.9FC28710
Content-Type: text/plain;
        charset="iso-8859-1"

I would like to display the results of a query in blocks of 10 with a Next
(submit type) button type feature.  Does any one have an example for me to
study or where I might read up on this?

Thanks in advance.


Lisa

------_=_NextPart_001_01C01147.9FC28710
Content-Type: text/html;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2651.75">
<TITLE>How to display data in blocks of 10 with a &quot;Next&quot; =
Feature</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2 FACE=3D"Arial">I would like to display the results of =
a query in blocks of 10 with a Next (submit type) button type =
feature.&nbsp; Does any one have an example for me to study or where I =
might read up on this?</FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Thanks in advance.</FONT>
</P>
<BR>

<P><FONT SIZE=3D2 FACE=3D"Arial">Lisa </FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C01147.9FC28710--
----------------------------------------------------------------------------
--
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.

------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to