Discover Antartica wrote:
> if I have 100 records in total and I want to display them 20 on a page with 
> arrows at the bottm saying "previous 20 records" or "next 20 records", how do 
> i do it in Coldfusion?

Do it with CFML! :)

Seriously, assuming all of the rows are returned by your query on each 
page... something like this....

<cfparam name="startrow" default="1">
<cfset maxrows = 20>
<cfquery name="qry" ...></cfquery>
<cfif qry.recordCount lt maxrows>
        <cfset startrow = 1>
</cfif>
<cfif startrow gt 1>
        <cfset prevurl = "foo.cfm?startRow=#prevStartRow#">
        <a href="<cfoutput>#prevUrl#</cfoutput>">PREV</A>
<cfelse>
        PREV
</cfif>
<cfif startRow + maxRows lt qry.recordCount>
        <cfset nextUrl = "foo.cfm?startRow = startRow + maxRows>
        <a href="<cfoutput>#nextUrl#</cfoutput>">NEXT</A>
<cfelse>
        NEXT
</cfif>
<hr>
<cfoutput query="qry" startrow="#startrow#" MAXROWS="#maxRows#">
  <!-- output your data here -->
</cfoutput>

-------------------
However, to be more efficient, if your database supports it, make sure 
the query only returns the data you need... ie, in MySQL:

SELECT * FROM EMP
LIMIT 20 OFFSET 21

Returns 20 rows starting with row 21... then the code above wouldn't 
quite work because it relies on qry.recordCount to contain the total 
number of rows in the query.

  - Rick

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:193717
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to