trailblazzyr55
asked on
Need a second look at a recordset paging, coming up with some errors????
I have, along with another coldfusion developer, come up with a custom tag for recordset paging in a variety of ways using a specific tag. Only when the records results are around 15 to 20 range I get a page number of zero. Not sure how to correct this quickly and am kinda pressed for time, can anyone offer some advice or a correction here or there? Thanks! Any help would be greatly appreciated!!
Here's the custom tag script....
<!------------------------ ---------- ---------- ---------- ---------- --------
NAME: CF_RecordSet
FILE: recordset.cfm
CREATED: 1/24/2004
LAST MODIFIED: 2/23/2004
VERSION: 1.0
AUTHOR: Dave Wheelock (dave@wheelockgroup.com)
DESCRIPTION: CF_RecordSet is a custom tag that will 'previous' and 'next' navigation for query result sets.
Input variables:
TOTALRECORDS: query recordcount
Required: YES
Datatype: number
DISPLAYCOUNT: number of records to display per page
Required: YES
Datatype: number
ADDITIONALURLPARAMS: any additional parameters required
Required: YES
Datatype: string
Output variables:
FWDURLPATH: Link to increase page number by 1
BCKURLPATH: Link to decrease page number by 1
STARTROW: Must be passed to the CFOUTPUT tag to display the records
DISPLAYCOUNT: Passes the displaycount back to the calling page
SHOWWHATRECORDS: String to display current recordset matches
CURRENTPAGE: current page number of recordset
NUMBEROFPAGES: number of pages in recordset
Example:
<CF_Recordset
TOTALRECORDS="#getproducts .recordcou nt#"
DISPLAYCOUNT="6"
ADDITIONALURLPARAMS="&cate gory=#cate gory#&myva r=yes">
* EXAMPLE NAVIGATION DISPLAY METHOD 1 (i.e. Page 3 of 8 (previous 2) (next 4)):
<cfoutput>Page #CurrentPage# of #NumberOfPages#   ;#CALLER.B CKURLPATH# &nbs p;#CALLER. FWDURLPATH #</cfoutpu t>
* EXAMPLE NAVIGATION DISPLAY METHOD 2 (i.e. Page 3, 12345678):
<cfoutput>Page #CurrentPage#, <cfloop index="ii" from="1" to="#NUMBEROFPAGES#"><cfse t currentstartrow = IncrementValue((#ii# * #DisplayCount#) - #DisplayCount#)><a href="category.cfm?StartRo w=#Current StartRow#& category=# category#" >#ii#</a>< /cfloop></ cfoutput>
* EXAMPLE NAVIGATION DISPLAY METHOD 3 (i.e. Page 3, (previous 2) 12345678 (next 4)):
<cfoutput>Page #CurrentPage#, #BCKURLPATH# <cfloop index="ii" from="1" to="#NUMBEROFPAGES#"><cfse t currentstartrow = IncrementValue((#ii# * #DisplayCount#) - #DisplayCount#)><a href="category.cfm?StartRo w=#Current StartRow#& category=# category#" >#ii#</a>< /cfloop>&n bsp;#FWDUR LPATH#</cf output>
* EXAMPLE NAVIGATION DISPLAY METHOD 4 (i.e. (previous 2) page 3 of 8 pages (next 4)):
<cfoutput>#BCKURLPATH# page #currentpage# of #NUMBEROFPAGES# pages #FWDURLPATH#</cfoutput>
[previous x] <<< x number of pages >>> [next x]
<CFOUTPUT query="GetProducts" STARTROW="#startrow#" MAXROWS="#DisplayCount#">
#ItemName#
</cfoutput>
COPYRIGHT: Copyright (C) 2004 by Dave Wheelock - Wheelock Group Inc., All Rights Reserved
KNOWN ISSUES: None
-------------------------- ---------- ---------- ---------- ---------- ------->
<CFSET TotalRecords = ATTRIBUTES.TotalRecords>
<CFSET DisplayCount = ATTRIBUTES.DisplayCount>
<CFSET AdditionalURLParams = ATTRIBUTES.AdditionalURLPa rams>
<CFIF Not IsDefined("URL.StartRow")>
<CFSET StartRow = 1>
<CFELSE>
<CFSET StartRow = URL.StartRow>
</CFIF>
<!--- VARS USED BY THE CFOUPUT, CONTROL NUMBER VIEWING //--->
<CFSET CALLER.StartRow = StartRow>
<CFSET CALLER.DisplayCount = DisplayCount>
<cfscript>
{
TotalRecords = evaluate('TotalRecords');
NumberOfPages = Ceiling(TotalRecords / displaycount);
{CurrentPage = 1;}
aPages = ArrayNew(1);
TempRecordCounter = 1;
for(i=1; i lte NumberOfPages; i=i+1)
{
LastPageRecord = TempRecordCounter + DisplayCount - 1;
if(LastPageRecord gt TotalRecords)
{LastPageRecord = TotalRecords;}
aPages[i] = "#TempRecordCounter#,#Last PageRecord #";
// record locator was specified
// now find the page where the record would be
if(isDefined("url.startrow "))
{
RecordFlag = url.startrow;
if((RecordFlag gte TempRecordCounter) and (RecordFlag lte LastPageRecord))
RecordOnPage = i;
}
TempRecordCounter = TempRecordCounter + DisplayCount;
}
TopRecord = ListGetAt(aPages[CurrentPa ge],1);
// if we're asked to remember the page
if(isDefined("RecordOnPage "))
{
// now set the current page to it.
CurrentPage = RecordOnPage;
// redefine top record
TopRecord = ListGetAt(aPages[CurrentPa ge],1);
}
////////////////////////// ////////// ////////// //
//What are the previous and next row to start positions
PrevStart = CurrentPage - 1;
NextStart = CurrentPage + 1;
}
</cfscript>
<!--- LINK TO MOVE FORWARD THROUGH THE RECORDS //--->
<CFSET NextStartRow = StartRow + DisplayCount>
<CFIF NextStartRow lte TotalRecords>
<CFSET TheseRecords = NextStartRow - 1> <!--- USED FOR DISPLAYING CURRENT RECORDSET //--->
<CFSET CALLER.FWDURLPATH = '<a href="#GetFileFromPath(Get TemplatePa th())#?Sta rtRow=#Nex tStartRow# #Additiona lURLParams #">NEXT ></a>'>
<CFELSE>
<CFSET TheseRecords = TotalRecords> <!--- USED FOR DISPLAYING CURRENT RECORDSET //--->
<CFSET CALLER.FWDURLPATH = ''>
</CFIF>
<!--- LINK TO MOVE BACKWARD THROUGH THE RECORDS //--->
<CFIF StartRow neq 1>
<CFSET LastStartRow = StartRow - DisplayCount>
<CFIF LastStartRow lte 0>
<CFSET LastStartRow = 1>
</CFIF>
<CFSET CALLER.BCKURLPATH = '<a href="#GetFileFromPath(Get TemplatePa th())#?Sta rtRow=#Las tStartRow# #Additiona lURLParams #">< PREV</a>'>
<CFELSE>
<CFSET CALLER.BCKURLPATH = ''>
</CFIF>
<!--- OUTPUT FOR CURRENT RECORDSET //--->
<CFSET CALLER.ShowWhatRecords = "Records #StartRow# thru #TheseRecords# of #TotalRecords# matches found">
<CFSET CALLER.currentpage = currentpage>
<CFSET CALLER.numberofpages = numberofpages>
<!------------------------ ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
START OF MOD - NEW CODE ADDED//
AUTHOR: Dave Wheelock (dave@wheelockgroup.com)
Edited By: Adam Leszinki (aleszinski@yahoo.com)
LAST MODIFIED: 2/23/2004
---ADDED OUTPUT VARIABLES---
* BEGINROW: Link to set beginning of recordset paging
* ENDROW: Link to set end to recordset paging
* FIRSTURLPATH: Sets link to take user to beginning
* LASTURLPATH: Sets link to take user to the end of a recordset
---ADDED INPUT VARIABLES---
***Used to set desired number of pages shown at once***
"Desired page setting should suite size of page and is recommended an odd integer be used"
PAGESET: query recordcount
Required: YES
Datatype: number
<CF_Recordset
TOTALRECORDS="#getproducts .recordcou nt#"
DISPLAYCOUNT="5"
ADDITIONALURLPARAMS="&cate gory=#cate gory#&myva r=yes">
PAGESET = "9"
* EXAMPLE NAVIGATION DISPLAY METHOD ADDED: (i.e. FIRST < PREV 5 6 7 8 9 10 11 12 13 NEXT > LAST ):
<cfoutput>#FIRSTURLPATH#</ cfoutput>< cfoutput># BCKURLPATH #</cfoutpu t>
<cfparam name="beginrow" default="1">
<cfoutput>
<cfloop index="ii" from="#beginrow#" to="#endrow#">
<cfset currentstartrow = IncrementValue(( #ii# * #DisplayCount#) - #DisplayCount#)>
<a href="category.cfm?StartRo w=#Current StartRow#& category=# category#& myvar=yes" > #ii # </a >
</cfloop>
</cfoutput> <cfoutput >#FWDURLPA TH#</cfout put><cfout put>#LASTU RLPATH#</c foutput>
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------->
<!---ADDED ATTRIBUTES--->
<CFSET PageSet = ATTRIBUTES.PageSet>
<!---Added Variables--->
<CFIF NumberOfPages LTE PageSet>
<CFSET PageSet = NumberOfPages>
</CFIF>
<CFSET PageNum = currentpage>
<CFSET PageVal = Int(PageSet / 2)>
<CFSET VAR1 = DisplayCount * NumberOfPages>
<CFSET MidPag = PageVal * IncrementValue(DisplayCoun t)>
<CFSET RowSet = VAR1 - MidPag>
<CFSET MidVar = NumberOfPages - PageVal>
<CFSET RemVar = TotalRecords - VAR1>
<!---End Added Parameters--->
<!---Increments pages setting and centers current page in middle--->
<CFIF PageNum LTE PageVal>
<CFSET beginrow = 1>
<CFSET endrow = PageSet>
<CFELSE>
<CFSET beginrow = PageNum - PageVal>
<CFSET endrow = PageNum + PageVal>
</CFIF>
<CFIF StartRow GTE RowSet>
<CFSET beginrow = MidVar - PageVal>
<CFSET endrow = MidVar + PageVal>
</CFIF>
<!---LINK TO FIRST RECORD--->
<CFIF StartRow NEQ 1>
<CFSET FirstPage = 1>
<CFSET CALLER.FIRSTURLPATH = '<a href="#GetFileFromPath(Get TemplatePa th())#?Sta rtRow=#Fir stPage##Ad ditionalUR LParams#"> FIRST</a>' >
<CFELSE>
<CFSET CALLER.FIRSTURLPATH = ''>
</CFIF>
<!---LINK TO LAST RECORD--->
<CFIF StartRow LTE TotalRecords - DisplayCount>
<CFSET LastPage = IncrementValue(VAR1) - DisplayCount>
<CFSET CALLER.LASTURLPATH = '<a href="#GetFileFromPath(Get TemplatePa th())#?Sta rtRow=#Las tPage##Add itionalURL Params#">L AST</a>'>
<CFELSE>
<CFSET CALLER.LASTURLPATH = ''>
</CFIF>
<CFSET CALLER.beginrow = beginrow>
<CFSET CALLER.endrow = endrow>
<!---//End of New Section Added--->
Here's the custom tag script....
<!------------------------
NAME: CF_RecordSet
FILE: recordset.cfm
CREATED: 1/24/2004
LAST MODIFIED: 2/23/2004
VERSION: 1.0
AUTHOR: Dave Wheelock (dave@wheelockgroup.com)
DESCRIPTION: CF_RecordSet is a custom tag that will 'previous' and 'next' navigation for query result sets.
Input variables:
TOTALRECORDS: query recordcount
Required: YES
Datatype: number
DISPLAYCOUNT: number of records to display per page
Required: YES
Datatype: number
ADDITIONALURLPARAMS: any additional parameters required
Required: YES
Datatype: string
Output variables:
FWDURLPATH: Link to increase page number by 1
BCKURLPATH: Link to decrease page number by 1
STARTROW: Must be passed to the CFOUTPUT tag to display the records
DISPLAYCOUNT: Passes the displaycount back to the calling page
SHOWWHATRECORDS: String to display current recordset matches
CURRENTPAGE: current page number of recordset
NUMBEROFPAGES: number of pages in recordset
Example:
<CF_Recordset
TOTALRECORDS="#getproducts
DISPLAYCOUNT="6"
ADDITIONALURLPARAMS="&cate
* EXAMPLE NAVIGATION DISPLAY METHOD 1 (i.e. Page 3 of 8 (previous 2) (next 4)):
<cfoutput>Page #CurrentPage# of #NumberOfPages#  
* EXAMPLE NAVIGATION DISPLAY METHOD 2 (i.e. Page 3, 12345678):
<cfoutput>Page #CurrentPage#, <cfloop index="ii" from="1" to="#NUMBEROFPAGES#"><cfse
* EXAMPLE NAVIGATION DISPLAY METHOD 3 (i.e. Page 3, (previous 2) 12345678 (next 4)):
<cfoutput>Page #CurrentPage#, #BCKURLPATH# <cfloop index="ii" from="1" to="#NUMBEROFPAGES#"><cfse
* EXAMPLE NAVIGATION DISPLAY METHOD 4 (i.e. (previous 2) page 3 of 8 pages (next 4)):
<cfoutput>#BCKURLPATH# page #currentpage# of #NUMBEROFPAGES# pages #FWDURLPATH#</cfoutput>
[previous x] <<< x number of pages >>> [next x]
<CFOUTPUT query="GetProducts" STARTROW="#startrow#" MAXROWS="#DisplayCount#">
#ItemName#
</cfoutput>
COPYRIGHT: Copyright (C) 2004 by Dave Wheelock - Wheelock Group Inc., All Rights Reserved
KNOWN ISSUES: None
--------------------------
<CFSET TotalRecords = ATTRIBUTES.TotalRecords>
<CFSET DisplayCount = ATTRIBUTES.DisplayCount>
<CFSET AdditionalURLParams = ATTRIBUTES.AdditionalURLPa
<CFIF Not IsDefined("URL.StartRow")>
<CFSET StartRow = 1>
<CFELSE>
<CFSET StartRow = URL.StartRow>
</CFIF>
<!--- VARS USED BY THE CFOUPUT, CONTROL NUMBER VIEWING //--->
<CFSET CALLER.StartRow = StartRow>
<CFSET CALLER.DisplayCount = DisplayCount>
<cfscript>
{
TotalRecords = evaluate('TotalRecords');
NumberOfPages = Ceiling(TotalRecords / displaycount);
{CurrentPage = 1;}
aPages = ArrayNew(1);
TempRecordCounter = 1;
for(i=1; i lte NumberOfPages; i=i+1)
{
LastPageRecord = TempRecordCounter + DisplayCount - 1;
if(LastPageRecord gt TotalRecords)
{LastPageRecord = TotalRecords;}
aPages[i] = "#TempRecordCounter#,#Last
// record locator was specified
// now find the page where the record would be
if(isDefined("url.startrow
{
RecordFlag = url.startrow;
if((RecordFlag gte TempRecordCounter) and (RecordFlag lte LastPageRecord))
RecordOnPage = i;
}
TempRecordCounter = TempRecordCounter + DisplayCount;
}
TopRecord = ListGetAt(aPages[CurrentPa
// if we're asked to remember the page
if(isDefined("RecordOnPage
{
// now set the current page to it.
CurrentPage = RecordOnPage;
// redefine top record
TopRecord = ListGetAt(aPages[CurrentPa
}
//////////////////////////
//What are the previous and next row to start positions
PrevStart = CurrentPage - 1;
NextStart = CurrentPage + 1;
}
</cfscript>
<!--- LINK TO MOVE FORWARD THROUGH THE RECORDS //--->
<CFSET NextStartRow = StartRow + DisplayCount>
<CFIF NextStartRow lte TotalRecords>
<CFSET TheseRecords = NextStartRow - 1> <!--- USED FOR DISPLAYING CURRENT RECORDSET //--->
<CFSET CALLER.FWDURLPATH = '<a href="#GetFileFromPath(Get
<CFELSE>
<CFSET TheseRecords = TotalRecords> <!--- USED FOR DISPLAYING CURRENT RECORDSET //--->
<CFSET CALLER.FWDURLPATH = ''>
</CFIF>
<!--- LINK TO MOVE BACKWARD THROUGH THE RECORDS //--->
<CFIF StartRow neq 1>
<CFSET LastStartRow = StartRow - DisplayCount>
<CFIF LastStartRow lte 0>
<CFSET LastStartRow = 1>
</CFIF>
<CFSET CALLER.BCKURLPATH = '<a href="#GetFileFromPath(Get
<CFELSE>
<CFSET CALLER.BCKURLPATH = ''>
</CFIF>
<!--- OUTPUT FOR CURRENT RECORDSET //--->
<CFSET CALLER.ShowWhatRecords = "Records #StartRow# thru #TheseRecords# of #TotalRecords# matches found">
<CFSET CALLER.currentpage = currentpage>
<CFSET CALLER.numberofpages = numberofpages>
<!------------------------
START OF MOD - NEW CODE ADDED//
AUTHOR: Dave Wheelock (dave@wheelockgroup.com)
Edited By: Adam Leszinki (aleszinski@yahoo.com)
LAST MODIFIED: 2/23/2004
---ADDED OUTPUT VARIABLES---
* BEGINROW: Link to set beginning of recordset paging
* ENDROW: Link to set end to recordset paging
* FIRSTURLPATH: Sets link to take user to beginning
* LASTURLPATH: Sets link to take user to the end of a recordset
---ADDED INPUT VARIABLES---
***Used to set desired number of pages shown at once***
"Desired page setting should suite size of page and is recommended an odd integer be used"
PAGESET: query recordcount
Required: YES
Datatype: number
<CF_Recordset
TOTALRECORDS="#getproducts
DISPLAYCOUNT="5"
ADDITIONALURLPARAMS="&cate
PAGESET = "9"
* EXAMPLE NAVIGATION DISPLAY METHOD ADDED: (i.e. FIRST < PREV 5 6 7 8 9 10 11 12 13 NEXT > LAST ):
<cfoutput>#FIRSTURLPATH#</
<cfparam name="beginrow" default="1">
<cfoutput>
<cfloop index="ii" from="#beginrow#" to="#endrow#">
<cfset currentstartrow = IncrementValue(( #ii# * #DisplayCount#) - #DisplayCount#)>
<a href="category.cfm?StartRo
</cfloop>
</cfoutput> <cfoutput
--------------------------
<!---ADDED ATTRIBUTES--->
<CFSET PageSet = ATTRIBUTES.PageSet>
<!---Added Variables--->
<CFIF NumberOfPages LTE PageSet>
<CFSET PageSet = NumberOfPages>
</CFIF>
<CFSET PageNum = currentpage>
<CFSET PageVal = Int(PageSet / 2)>
<CFSET VAR1 = DisplayCount * NumberOfPages>
<CFSET MidPag = PageVal * IncrementValue(DisplayCoun
<CFSET RowSet = VAR1 - MidPag>
<CFSET MidVar = NumberOfPages - PageVal>
<CFSET RemVar = TotalRecords - VAR1>
<!---End Added Parameters--->
<!---Increments pages setting and centers current page in middle--->
<CFIF PageNum LTE PageVal>
<CFSET beginrow = 1>
<CFSET endrow = PageSet>
<CFELSE>
<CFSET beginrow = PageNum - PageVal>
<CFSET endrow = PageNum + PageVal>
</CFIF>
<CFIF StartRow GTE RowSet>
<CFSET beginrow = MidVar - PageVal>
<CFSET endrow = MidVar + PageVal>
</CFIF>
<!---LINK TO FIRST RECORD--->
<CFIF StartRow NEQ 1>
<CFSET FirstPage = 1>
<CFSET CALLER.FIRSTURLPATH = '<a href="#GetFileFromPath(Get
<CFELSE>
<CFSET CALLER.FIRSTURLPATH = ''>
</CFIF>
<!---LINK TO LAST RECORD--->
<CFIF StartRow LTE TotalRecords - DisplayCount>
<CFSET LastPage = IncrementValue(VAR1) - DisplayCount>
<CFSET CALLER.LASTURLPATH = '<a href="#GetFileFromPath(Get
<CFELSE>
<CFSET CALLER.LASTURLPATH = ''>
</CFIF>
<CFSET CALLER.beginrow = beginrow>
<CFSET CALLER.endrow = endrow>
<!---//End of New Section Added--->
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
B'Rgrds
~trail