CFLib.org – Common Function Library Project

NextN(count, numToDiplay, href[, startMarker])

Last updated October 10, 2002

author

Joel Richards

Version: 2 | Requires: CF5 | Library: UtilityLib

Description:
Displays a list of pages with links to records within.

Return Values:
Returns a string.

Example:

<cfoutput>
<p>
#nextN(30,5,"index.cfm","start")#
</p>
</cfoutput>
<!--- pretend we are on start=16 ---->
<cfset url.start = 16>
<cfoutput>
<p>
#nextN(30,5,"index.cfm","start")#
</p>
</cfoutput>

Parameters:

Name Description Required
count The record count of the query. Yes
numToDiplay How many records are displayed per page. Yes
href The URL to link to. This can include query string information. Yes
startMarker The name of the url variable that will signify which record to start with. Defaults to "nextStart." No

Full UDF Source:

/**
 * Enables next 'n' browsing of a record set.
 * Modified by Ray Camden to: Make the url var dynamic, and disable the link on current page.
 * 
 * @param count      The record count of the query. (Required)
 * @param numToDiplay      How many records are displayed per page. (Required)
 * @param href      The URL to link to. This can include query string information. (Required)
 * @param startMarker      The name of the url variable that will signify which record to start with. Defaults to "nextStart." (Optional)
 * @return Returns a string. 
 * @author Joel Richards (joel@brainstormin.net) 
 * @version 2, October 10, 2002 
 */
function nextN(count,numToDisplay,href) {
    var totalRecords = count; // query recordcount
    var NsListLength = ceiling(totalRecords / numToDisplay); // this will give us the number of pages needed to display the full record set
    var NextStartList = ""; // list of start numbers
    var nextStart=1; // where to start outputting record
    var content = "";
    var i = 1;
    var startMarker = "nextStart"; // name of the url var to create
    
    if(arrayLen(arguments) gte 4) startMarker = arguments[4];
    
    for ( i = 1; i lte NsListLength; i = i + 1 ) {
        NextStartlist = listAppend(NextStartlist,nextStart); 
        // this will be the next start number in our list
        nextStart = nextStart + numToDisplay;
    }

    //output the links
    if (len(NextStartList) gt 1) {
        content = "Page ";
        for (i = 1; i lte listlen(NextStartList);  i = i + 1) {
            if(isDefined("url.#startMarker#") and url[startMarker] is listGetAt(NextStartList,i)) content = content & i;
            else content = content & " <a href=""" & href & "&#startMarker#=" & listGetAt(NextStartList,i) & """>" & i & "</a> ";
        } 
    }

    return content;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson