Solved

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

Posted on 2004-04-19
2
286 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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

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…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now