EasyCFM.COM ColdFusion Forums / Coding Help! / CFLOOP Sass!

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: CFLOOP Sass!

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

][ce
03-30-2005 @ 1:40 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 25
Joined: Jul 2003

Hey Everybody!

My advance apologies if this is a lengthy post, I just want to make sure I'm clear in my problem:
I'm having some serious problems with a Previous/Next utility I'm using.
Basically, I have a search form that displays a recordset, which I then display x number of records per page - let's just say 10, for argument's sake.

Here is the code I'm using to navigate between pages:

<!--- Previous Link Here... --->

<CFLOOP FROM="1" TO="#DisplayPages#" INDEX="ThisPage">
     <CFIF ThisPage IS PageNum>
          <B>#ThisPage#</B>
     <CFELSE>
          <CFSET PageNumStart = (((ThisPage - 1) * OnEachPage) + 1)>
          <A HREF="pcm.cfm?StartRow=#PageNumStart#&PageNum=#ThisPage#">#ThisPage#</A>
     </CFIF>
</CFLOOP>

<!--- Next Link Here... --->


So, if I've my code is clear enough, you'll see that between the Previous and Next links, I'm trying to display the number of pages, so the end user is able to quickly select a page to go to, like this:

<Previous  1 2 3 4 5 6  Next>
(bold indicating the current page that the user is on)

Although, if the recordset is large, I could potentially end up with like 30+ numbers, which is too much.  What I'd like is for the loop to recognize if there's more than 12 or 15 pages worth of records, and to display the page numbers like this:

<Previous  1 2 3 ... 9 10 11  Next>

AND, to add to the complexity, if the current page is somewhere in the middle, it should be like this:

<Previous  1 2 3 ... 7 8 9 ... 13 14 15  Next>

So, what I was trying to do is something like:

<CFLOOP FROM="1" TO="#DisplayPages#" INDEX="ThisPage">
     <CFIF ThisPage IS PageNum>
          <B>#ThisPage#</B>
     <CFELSE>
          <CFSET PageNumStart = (((ThisPage - 1) * OnEachPage) + 1)>
          <A HREF="pcm.cfm?StartRow=#PageNumStart#&PageNum=#ThisPage#">#ThisPage#</A>
     </CFIF>

     <CFIF #ThisPage# EQ 3 AND #DisplayPages# GT 12>
          <CFSET ThisPage = 7>
          ...
     </CFIF>
</CFLOOP>

... or something like that.

but CFLOOP doesn't work like that - I can't change the index value...  so, now, I don't know what to do.  Does anybody have any suggestions?
Any help would be greatly appreciated!

Also... if I wasn't clear in my above explanation, which is ENTIRELY possible... just let me know, and I'll be happy to clarify.

Thanks!
Dave

kene
03-30-2005 @ 2:20 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 180
Joined: Sep 2003

You can start with this custom tag.
http://www.johnstons.org/wdc/pub/cfusion/customtags/CF_PageThru/CF_PageThru.html

It will give you the basic structure you are seeking. Whether you can modify it easily to create the display you are seeking is an open question. There is enough documentation regarding the tag to help you understand how it operates and possibly customize it for your situation.

I used it a couple of years ago and made some modifications without too much trouble, but I haven't done anything with it recently.



][ce
03-30-2005 @ 3:17 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 25
Joined: Jul 2003

This definitely points me in the right direction.  I'll see what I can do.
Thanks for your help!


Website Designed and Developed by Pablo Varando.