EasyCFM.COM ColdFusion Forums / Coding Help! / Previous/Next Page

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Previous/Next Page -- page: 1 2

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

bxrunner
08-24-2009 @ 8:40 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 3
Joined: Aug 2009

Hi, am new to coldfusion and been asked by my boss to add a previous/next page to one of our pages.  I do get the next and previous to function, only it keeps repeating the same page, it won't jump to the next or previous.  Here is my code. Any help will be greatly appreciated.
<!---Query the Subject type--->
<cfquery name="GetSubject" datasource="itfaq">
     Select SubjectType
    From   tblFAQ
    Order by SubjectType
  </cfquery>

          <!---Initialize the startRow variable to 1>--->

          <cfparam name="url.startRow" default="1">
             <cfset atEachTime ="2">
               <cfset lastRow= url.startRow + atEachTime -1>
          <cfif lastRow GT GetFAQ.RecordCount>
          
             <span class="c">
             <cfset lastRow = GetFAQ.RecordCount>     
            </span>
          </cfif>
        
<cfoutput><span class="c">
FAQ #url.startRow# of #GetFAQ.RecordCount#
</span></cfoutput>    
        
        
        <span class="c">
        <!---Display the appropiate records using the values above--->
        <cfoutput query="GetSubject" startRow="#url.startRow#" maxRows="#atEachTime#"></cfoutput>
          
        <!---Display the previous/next links--->
          
        <!--- Only display the previous page link if this is not already the first page. --->
        <!--- The StartRow variable is passed in the URL to determine what row the previous block will start displaying. --->
          <cfif url.startRow NEQ 1>
            <cfset previousStart = url.startRow - atEachTime>
            <cfoutput>
              <a href="?page=faq2&startRow=#previousStart#"><<Previous Page</a>
           </cfoutput>
         </cfif>
        
         <!--- Only display the next page link if this is not already the last page. --->
           <!--- The StartRow variable is passed in the URL to determine what row the next block will start displaying. --->
           <cfif lastRow NEQ GetFAQ.RecordCount>
             <cfset nextStart = lastRow + 1>
             <cfoutput>
               <a href="?page=faq2&startRow=#nextStart#">Next Page>></a>
            </cfoutput>  
         </cfif>  
  Regards,



Vee

nmiller
08-24-2009 @ 9:13 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 773
Joined: Apr 2003

http://www.easycfm.com/coldfusion/forums/viewmessages.cfm
?Forum=12&Topic=14102&keywords=next%20n

Nathan Miller
NM Consulting

dlackey
08-24-2009 @ 9:18 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 935
Joined: Jun 2007

I think you issue is with the following code.  I just did a quick glance and this popped out at me.

<cfset lastRow= url.startRow + atEachTime -1>


If StartRow =1 and atEachTime = 2 and then you are subtracting -1.



Cheers,
Chip

Webmaster
08-24-2009 @ 3:06 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4533
Joined: Jan 2002

Save yourself the trouble and use a custom tag.

http://www.johnstons.org/wdc/pub/cfusion/customtags/CF_PageThru/CF_PageThru.html

I've used it many times and it works like a charm.

P

Pablo Varando
Senior Application Architect
EasyCFM.COM, LLC.

904.483.1457 \\ mobile
webmaster@easycfm.com \\email

\m/ (>.<) \m/
--- rock on ---

dlackey
08-24-2009 @ 5:11 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 935
Joined: Jun 2007

@webmaster:  +1

I just coded a simple database query and that thing is very slick and easy.  Thanks for sharing.

Cheers,
Chip

Webmaster
08-24-2009 @ 5:29 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4533
Joined: Jan 2002

You're welcome... hope it helps!

Pablo Varando
Senior Application Architect
EasyCFM.COM, LLC.

904.483.1457 \\ mobile
webmaster@easycfm.com \\email

\m/ (>.<) \m/
--- rock on ---

bxrunner
08-25-2009 @ 12:12 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 3
Joined: Aug 2009

Thanks but I don't see a problem with that piece of code, but thanks for trying to help.

Regards,
Vee

Vee

bxrunner
08-25-2009 @ 12:18 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 3
Joined: Aug 2009

Thank you.  Am probably better of.

Regards,

Vee

Vee

MIGhunter
08-27-2009 @ 7:31 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 569
Joined: Apr 2006

Not sure about that code either.  Like Pablo said, CFC is the way to go.  If you want something customizable, use:
http://www.dopefly.com/projects/pagination/

Examples:
http://www.dopefly.com/projects/pagination/examples/

Lyndon
09-10-2009 @ 9:13 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 66
Joined: Jun 2004

What version of CF is required to use this CFC?

Lyndon

PAGE: 1 2
Sponsored By...
iOpenSoft, LLC is a Houston, Texas Advanced Technology Studio Specializing in Web Design, Web Development, iPhone App Development and Android App Development.