4 Replies - 2689 Views - Last Post: 01 September 2005 - 07:37 PM Rate Topic: -----

#1 wendy_w  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 02-June 05

Show only a few results at a time

Posted 30 August 2005 - 07:16 AM

I have a page that displays data based on what a user puts into a form on the previous page. My problem is that there are often over 30,000 results and the browsers keep locking up. How do I go about only showing a few results at a time and allowing the user to click next to see a few more results?
Is This A Good Question/Topic? 0
  • +

Replies To: Show only a few results at a time

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Show only a few results at a time

Posted 30 August 2005 - 07:31 AM

There are a few ways to accomplish this...probably the top two are:

1. Pull all the results into one array...display a set amount of that array the first time...advise the user to click for more...that click would run a function that takes the last number displayed as a parameter, and runs the next set.

2. Pull only the first set of records...provide the user with a more link...that link will refresh the current page, but with an additional variable in the querystring or form...that variable will specify the next record to pull up, run a loop for another set.

Either way is good.
Was This Post Helpful? 0
  • +
  • -

#3 wendy_w  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 02-June 05

Re: Show only a few results at a time

Posted 30 August 2005 - 08:20 AM

do you know of any good online examples I can look at. I can't visualize what to do in my head.
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Show only a few results at a time

Posted 30 August 2005 - 08:37 AM

Try something like this...I'm not sure how good it is, I'm not really a CF programmer...
Was This Post Helpful? 0
  • +
  • -

#5 supernova333  Icon User is offline

  • D.I.C Addict

Reputation: 4
  • View blog
  • Posts: 590
  • Joined: 12-March 02

Re: Show only a few results at a time

Posted 01 September 2005 - 07:37 PM

Here's an example of this in action: Website with record nav

Below is the code that would do that for you. It assumes you are using a table named "mytable" with the columns ID, title, and created. I set the RowsPerPage to 1000 for you which is still a lot but you've got 30,000 to display. On a side note, you might want to consider a search-driven display instead of showing everything. Nobody is going to like going through 30,000 rows to find what they are looking for.

Anyway, the code selects all the rows, then uses cfsavecontent to generate a navigation bars contained in the variable "navbar". You can then put that anywhere on your page that you want it. I put it at the top and bottom of this page. After that is the loop that displays the correct segment of records you want to show the user.

Play around with it and let us know if you have questions or need help modifying it.

<cfquery datasource="DSN" name="myQuery">
select ID, title, created
from mytable
order by created desc
</cfquery>

<cfset RowsPerPage = 1000>
<cfparam name="StartRow" default="1" type="numeric">
<cfset TotalRows = myQuery.recordCount>
<cfset EndRow = Min(StartRow + RowsPerPage - 1, TotalRows)>
<cfset StartRowNext = EndRow + 1>
<cfset StartRowBack = StartRow - RowsPerPage>
  
<cfoutput>
<cfsavecontent variable="navbar">
<table width="100%" cellpadding="3" cellspacing="1" border="0" bgcolor="##EEEEEE">
<tr>
	<td><cfif StartRowBack gt 0>
 	 <a href="#cgi.SCRIPT_NAME#?StartRow=#StartRowBack#">&lt; Back</a>
  </cfif>
  <cfset ThisPage = 1>
  <cfloop from="1" to="#TotalRows#" step="#RowsPerPage#" index="PageRow">
 	 <cfset IsCurrentPage = (PageRow gte StartRow) and (PageRow lte EndRow)>
 	 <cfif IsCurrentPage>
    <b>#ThisPage#</b>
 	 <cfelse>
    <a href="#cgi.SCRIPT_NAME#?StartRow=#PageRow#">#ThisPage#</a>
 	 </cfif>
 	 <cfset ThisPage = ThisPage + 1>
  </cfloop>
  <cfif StartRowNext lte TotalRows>
 	 <a href="#cgi.SCRIPT_NAME#?StartRow=#StartRowNext#">Next &gt;</a>
  </cfif></td>
	<td align="right"><b>#StartRow#</b> to <b>#EndRow#</b> of <b>#TotalRows#</b></td>
</tr>
</table>
</cfsavecontent>

#navbar#
<br>

<table cellpadding="2" cellspacing="1" border="0" width="100%">
<cfloop query="myQuery" startrow="#StartRow#" endrow="#EndRow#">
	<tr<cfif currentRow mod 2> bgcolor="##F3F0E8"</cfif>> 
  <td>
 	 <a href="displaypage.cfm?ID=#ID#"><b>#title#</b></a><br>
 	 #DateFormat(created, "m/d/yyyy")# - <a href="displaypage.cfm?ID=#ID#">[Read Full Story]</a><br>
  </td>
	</tr>
</cfloop>
</table>
<br>
#navbar#
</cfoutput>

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1