• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Simple Logic but annoying

Participant ,
Apr 23, 2007 Apr 23, 2007

Copy link to clipboard

Copied

I got this code from a web site ...it seems easy....The trouble I am having is : when the page loads it shows 10 record per page but when I click next link it shows 20 records on the page...another next will populate 30 records on page...I need 10 records on each navigation...Any help :D

<cfparam name="start" type="numeric" default="1">
<cfparam name="step" type="numeric" default="10">
<cfquery datasource="..." name="queryResults">
select * from table
</cfquery>
<cfif queryResults.recordcount gt 0>
<cfoutput>
<p>
<!--- if past start --->
<cfif (start-step-step) gt 1>
<a href="#cgi.SCRIPT_NAME#?start=1"><img src="/images/beginning_blue.png" alt="Beginning" align="absbottom"></a>
</cfif>
<cfif start gt 1>
<a href="#cgi.SCRIPT_NAME#?start=#start-step#"><img src="/images/previous_blue.png" alt="Previous" align="absbottom"></a>
</cfif>
<strong>#start# - #iif(start + step gt queryResults.recordcount,queryResults.recordcount,start + step-1)# of #queryResults.recordcount# records</strong>
<!--- if still some not displayed --->
<cfif (start + step) lte queryResults.recordcount>
<a href="#cgi.SCRIPT_NAME#?start=#start+step#"><img src="/images/next_blue.png" alt="Next" align="absbottom"></a>
</cfif>
<cfif (start+step+step) lte queryResults.recordcount>
<a href="#cgi.SCRIPT_NAME#?start=#queryResults.recordcount-step+1#"><img src="/images/end_blue.png" alt="End" align="absbottom"></a>
</cfif>
</p>
</cfoutput>
</cfif>
<cfloop query="queryResults" startrow="#start#" maxrow="#start + step-1#">
...... output query here
</cfloop>
TOPICS
Advanced techniques

Views

263

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2007 Apr 23, 2007

Copy link to clipboard

Copied

There is an example that does just this in the CF help look-up cfquery / example

I've posted the example below

Example
<!--- This example shows the use of CreateTimeSpan with CFQUERY ------>
<!--- to cache a record set. Define startrow and maxrows to ---->
<!--- facilitate 'next N' style browsing. ---->
<cfparam name="MaxRows" default="10">
<cfparam name="StartRow" default="1">
<!--------------------------------------------------------------------
Query database for information if cached database information has
not been updated in the last six hours; otherwise, use cached data.
--------------------------------------------------------------------->
<cfquery
name="GetParks" datasource="cfdocexamples"
cachedwithin="#CreateTimeSpan(0, 6, 0, 0)#">
SELECT PARKNAME, REGION, STATE
FROM Parks
ORDER BY ParkName, State
</cfquery>
<!--- Build HTML table to display query. ------------------------->
<table cellpadding="1" cellspacing="1">
<tr>
<td bgcolor="f0f0f0">
 
</td>
<td bgcolor="f0f0f0">
<b><i>Park Name</i></b>
</td>
<td bgcolor="f0f0f0">
<b><i>Region</i></b>
</td>
<td bgcolor="f0f0f0">
<b><i>State</i></b>
</td>
</tr>
<!--- Output the query and define the startrow and maxrows parameters.
Use the query variable CurrentCount to keep track of the row you
are displaying. ------>
<cfoutput query="GetParks" startrow="#StartRow#" maxrows="#MaxRows#">
<tr>
<td valign="top" bgcolor="ffffed">
<b>#GetParks.CurrentRow#</b>
</td>
<td valign="top">
<font size="-1">#ParkName#</font>
</td>
<td valign="top">
<font size="-1">#Region#</font>
</td>
<td valign="top">
<font size="-1">#State#</font>
</td>
</tr>
</cfoutput>
<!--- If the total number of records is less than or equal
to the total number of rows, then offer a link to
the same page, with the startrow value incremented by
maxrows (in the case of this example, incremented by 10). --------->
<tr>
<td colspan="4">
<cfif (StartRow + MaxRows) LTE GetParks.RecordCount>
<cfoutput><a href="#CGI.SCRIPT_NAME#?startrow=#Evaluate(StartRow + MaxRows)#">
See next #MaxRows# rows</a></cfoutput>
</cfif>
</td>
</tr>
</table>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 23, 2007 Apr 23, 2007

Copy link to clipboard

Copied

LATEST
The mistery solved.. You can define step variable as <cfset step=10> instead of <cfparam name="step" type="numeric" default="10">

Then replace maxrow with #step#

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation