CFLib.org – Common Function Library Project

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

Last updated October 10, 2002

Version: 2 | Requires: ColdFusion 5 | Library: UtilityLib

 
Rated 1 time(s). Average Rating: 4.0

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

Return Values:
Returns a string.

Example:

view plain print about
<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:

view plain print about
<cfscript>
/**
 * 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;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
3 day(s) ago

Will Belden Will Belden added
longTime
9 day(s) ago

James Sleeman James Sleeman added
quickSort
19 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
22 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson