Solved

Need a second look at a recordset paging, coming up with some errors????

Posted on 2004-04-19
2
290 Views
Last Modified: 2013-12-24
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.recordcount#"
                          DISPLAYCOUNT="6"
                          ADDITIONALURLPARAMS="&category=#category#&myvar=yes">
                        
                  *      EXAMPLE NAVIGATION DISPLAY METHOD 1 (i.e. Page 3 of 8 (previous 2) (next 4)):
                        <cfoutput>Page #CurrentPage# of #NumberOfPages#&nbsp;&nbsp;#CALLER.BCKURLPATH#&nbsp;&nbsp;#CALLER.FWDURLPATH#</cfoutput>
                        
                  *      EXAMPLE NAVIGATION DISPLAY METHOD 2 (i.e. Page 3, 12345678):
                        <cfoutput>Page #CurrentPage#, <cfloop index="ii" from="1" to="#NUMBEROFPAGES#"><cfset currentstartrow = IncrementValue((#ii# * #DisplayCount#) - #DisplayCount#)><a href="category.cfm?StartRow=#CurrentStartRow#&category=#category#">#ii#</a></cfloop></cfoutput>
                        
                  *      EXAMPLE NAVIGATION DISPLAY METHOD 3 (i.e. Page 3, (previous 2) 12345678 (next 4)):
                        <cfoutput>Page #CurrentPage#, #BCKURLPATH#&nbsp;<cfloop index="ii" from="1" to="#NUMBEROFPAGES#"><cfset currentstartrow = IncrementValue((#ii# * #DisplayCount#) - #DisplayCount#)><a href="category.cfm?StartRow=#CurrentStartRow#&category=#category#">#ii#</a></cfloop>&nbsp;#FWDURLPATH#</cfoutput>

                  *      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.AdditionalURLParams>

<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#,#LastPageRecord#";
                                    
                                    // 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[CurrentPage],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[CurrentPage],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(GetTemplatePath())#?StartRow=#NextStartRow##AdditionalURLParams#">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(GetTemplatePath())#?StartRow=#LastStartRow##AdditionalURLParams#">< 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.recordcount#"
                                DISPLAYCOUNT="5"
                                ADDITIONALURLPARAMS="&category=#category#&myvar=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#</cfoutput>&nbsp;
                <cfparam name="beginrow" default="1">
                      <cfoutput>
                   <cfloop index="ii" from="#beginrow#" to="#endrow#">
                 <cfset currentstartrow = IncrementValue(( #ii# * #DisplayCount#) - #DisplayCount#)>
               <a href="category.cfm?StartRow=#CurrentStartRow#&category=#category#&myvar=yes">&nbsp;#ii#&nbsp;</a>
                    </cfloop>
            </cfoutput>&nbsp;<cfoutput>#FWDURLPATH#</cfoutput><cfoutput>#LASTURLPATH#</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(DisplayCount)>
<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(GetTemplatePath())#?StartRow=#FirstPage##AdditionalURLParams#">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(GetTemplatePath())#?StartRow=#LastPage##AdditionalURLParams#">LAST</a>'>
<CFELSE>
      <CFSET CALLER.LASTURLPATH = ''>
</CFIF>

<CFSET CALLER.beginrow = beginrow>
<CFSET CALLER.endrow = endrow>

<!---//End of New Section Added--->
0
Comment
Question by:trailblazzyr55
2 Comments
 
LVL 18

Accepted Solution

by:
Plucka earned 500 total points
ID: 10866125
Hi trailblazzyr55,

NumberOfPages = int((TotalRecords-1)/displaycount)+1


Regards
Plucka
0
 
LVL 20

Author Comment

by:trailblazzyr55
ID: 10866253
Thanks, that was quick and yeah I can see that, thanks for your help!! Really appreciate it!

B'Rgrds

~trail
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Redirect website ! 4 54
Script 12 175
Unsearchable in Google,Yahoo and Bing. 6 63
Asp.net Hosting Plan security, reliable, stable 1 79
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question