4 Replies Latest reply on Apr 15, 2007 8:20 PM by WOLFcfm

    Fixing error on "prev/next" code

    WOLFcfm Level 1
      This is the code I have to navigate through the database by previous and next links, the issue I'm having is for the previous when i click on the previous link, it stays on the same page and the issue i have with the next link is, it works fine up until there is no more information from the database to be displayed and if at that point i click on the next link the page gives an error. not sure how to fix this, can anyone help?


      <CFPARAM NAME="start" DEFAULT="1">
      <CFIF start + 2 GT displayinfo.RecordCount>
      <CFSET maxRows = displayinfo.RecordCount - start>
      <CFELSE>
      <CFSET maxRows = 2>
      </CFIF>

      <CFOUTPUT QUERY="displayinfo" STARTROW=#start# MAXROWS=#maxRows#>
      #name# <br> #address# <br><br>
      </CFOUTPUT>


      <cfif displayinfo.recordcount gt 2>
      <CFOUTPUT>
      <!--- next --->
      <CFSET start = start + 2>
      <CFIF start GT displayinfo.RecordCount>
      <CFSET start = 1>
      </CFIF>
      <A HREF="/test.cfm?n=#url.n#&start=#start#"><img src="/images/next-text-arrow.gif" border="0"></A>


      <!--- previous --->
      <CFSET start = start - 10>
      <CFIF start LE 0>
      <CFSET start = (displayinfo.RecordCount \ 10) & 1>
      </CFIF>
      <A HREF="/test.cfm?n=#url.n#&start=#start#"><img src="/images/prev-text-arrow.gif" border="0"></A>


      </CFOUTPUT>
      </cfif>
        • 1. Re: Fixing error on &quot;prev/next&quot; code
          The ScareCrow Level 1
          <!---Set your param--->

          <cfparam name="StartRow" default="1">
          <cfparam name="MaxRows" default="2">
          <cfparam name="next" default="0">
          <cfparam name="previous" default="0">

          <!--- Output your query --->
          <CFOUTPUT QUERY="displayinfo" STARTROW=#startRow# MAXROWS=#maxRows#>
          #name# <br> #address# <br><br>
          </CFOUTPUT>

          <!--- set the next/previous --->
          <cfset previous = startRow - MaxRows>
          <cfset next = startRow + maxRows>

          <!--- dispay previous the link --->
          <cfif previous GT 0>
          <A HREF="/test.cfm?n=#url.n#&startRow=#previous#"><img src="/images/prev-text-arrow.gif" border="0"></A>
          </cfif>

          <!--- display next link --->
          <cfif next LTE displayinfo.recordCount>
          <A HREF="/test.cfm?n=#url.n#&startRow=#next#"><img src="/images/next-text-arrow.gif" border="0"></A>
          </cfif>

          Ken
          • 2. Fixing error on &quot;prev/next&quot; code
            WOLFcfm Level 1
            Hey scarecrow, thanks for the help but there seems to be a minor issue cause im getting this message:

            The value "" cannot be converted to a number

            and in the url:
            &startRow=#next#


            I really dont know what it could be, any idea??
            • 3. Re: Fixing error on &quot;prev/next&quot; code
              The ScareCrow Level 1
              You need to enclose the next/previous links in cfoutput

              Ken
              • 4. Fixing error on &quot;prev/next&quot; code
                WOLFcfm Level 1
                Here is the part of the code you asked for:

                <cfset previous = startRow - MaxRows>
                <cfset next = startRow + maxRows>

                <cfoutput>
                <!--- dispay previous the link --->
                <cfif previous GT 0>
                <A HREF="/test.cfm?n=#url.n#&startRow=#previous#"><img src="/images/previous-text-arrow.gif" border="0"></A>
                </cfif>
                </cfoutput>

                <cfoutput>
                <!--- display next link --->
                <cfif next LTE displayinfo.recordCount>
                <A HREF="/test.cfm?n=#url.n#&startRow=#next#"><img src="/images/next-text-arrow.gif" border="0"></A>
                </cfif>
                </cfoutput>

                Thanks again for the help!