Solved

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

Posted on 2004-04-19
2
293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

729 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