3 Replies Latest reply on Nov 7, 2012 6:41 AM by cf_junkie

    Previous week / Next Week

    Lizz1912

      How can i implement Previous week / Next Week, like previous n / next n records?

       

      Can you please send me links for implmentation code or help me implement?.

      Please help.

      thank you.

       

      Previous / Next n Records

      http://tutorial20.easycfm.com/index.cfm?fuseaction=tutorial&tutorialID=20http://tutorial20.easycfm.com/

        • 1. Re: Previous week / Next Week
          BKBK Adobe Community Professional & MVP

          Your easycfm link seems a good start.

          • 2. Re: Previous week / Next Week
            Aegis Kleais Level 3

            It really depends on your RDBMS as well, since mySQL supports functions that easily allow for you to capture just the data you want, while MSSQL requires you to just about pull back the whole recordset and then selectively retrieve a subset (the size of the pagination) from it.

             

            For example, MSSQL 2012 finally introduced the standards-compliant FETCH and OFFSET keywords, so you could do something like

             

            SELECT

            field1,

            field2,

            field3

            FROM table

            WHERE

            this=that

            ORDER BY primaryKey

            OFFSET 5 ROWS

            FETCH NEXT 5 ROW ONLY

             

            Since ordering by primaryKey (assume 1, 2, 3, 4, etc)  This would return the record starting at 6 and give you 5 records worth (to ID 10).

             

            That way CF can just send the RDBMS system the offset (what page you're on) and the fetch size (the amount of records per page).  Then it's just a case of math to determine the text of "Next X records", etc.

            • 3. Re: Previous week / Next Week
              cf_junkie Level 1

              This is how i make the Next and previous link.

               

              == At the top of the page ==

              <cfparam name="URL.StartRow" default="1">

               

              <cfset NextRow = URL.StartRow + 25 />

              <cfset PreviousRow = URL.StartRow - 25 />

               

              <cfif PreviousRow LTE 0>

                <cfset PreviousRow = 1 />

              </cfif>

               

              == Next and previous links ==

              <cfif NextRow LTE QueryName.RecordCount >

                <a href="#CGI.SCRIPT_NAME#?StartRow=#NextRow#">Next page</a>

              <cfelse>

                 

              </cfif>

               

              <cfif PreviousRow LT URL.StartRow>

                <a href="#CGI.SCRIPT_NAME#?StartRow=#PreviousRow#">Previous</a>

              <cfelse>

                 

              </cfif>

               

              == Query results ==

              <cfoutput query="QueryName" startrow="#URL.StartRow#" maxrows="25">

              #Your output goes here#

              </cfouput>