Page Navigation Help

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Page Navigation Help

    I have this code that I've been working with for a couple years now. It has
    served me well, using it for page numbering one pages that have few results.
    The problem now is that if I have a result of, say 2,000 or more and a page
    display of about 28, that there are over a hundred pages on the navigation.
    Is there a way to limit the number of pages to display a next, previous,
    1,2,3,4,5,6,7,8,9,10, ..., next 10 pages, previous 10 pages? Here is the code
    that I've been using: <cfquery name='getStuff' datasource='myData'> select *
    from myTable order by ID desc </cfquery> <!--- PAGE NUMBER DISPLAY --->
    <CFSET RowsPerPage = 28> <cfif #ParameterExists(url.start)# is 'No'> <cfset
    curpage = 1> <cfelse> <cfset curPage = 1 + ((#url.start#-1)/#RowsPerPage#)>
    </cfif> <CFPARAM NAME='URL.StartRow' DEFAULT='1' TYPE='numeric'> <CFSET
    TotalRows = getStuff.RecordCount> <CFSET EndRow = Min(URL.StartRow +
    RowsPerPage - 1, TotalRows)> <CFSET StartRowNext = EndRow + 1> <CFSET
    StartRowBack = URL.StartRow - RowsPerPage> <cfset PrevStart = Start - MaxRows>
    <cfset NextStart = Start + MaxRows> <cfset DisplayPage = Start + MaxRows - 1>
    <cfset End = NextStart - 1> <!--- END PAGE NUMBER DISPLAY ---> <cfif
    PrevStart GTE 1> <cfoutput><cfset prev=#url.start# - #maxrows#><a
    href='#CGI.SCRIPT_NAME#?Start=#prev#&amp;next=#max rows#'>&amp;lt;&amp;lt;Previou
    s</a></cfoutput> <cfelse> &amp;lt;&amp;lt;Previous </cfif> <!--- Simple 'Page'
    counter, starting at first 'Page' ---> <cfset thispage = 1> <!--- Loop thru
    row numbers, in increments of RowsPerPage ---> <cfloop from='1'
    to='#TotalRows#' step='#RowsPerPage#' index='PageRow'> <!--- Detect whether
    this 'Page' currently being viewed ---> <cfset iscurrentpage = (pagerow gte
    url.startrow) and (pagerow lte endrow)> <!--- If this 'Page' is current page,
    show without link ---> <cfif iscurrentpage> | <cfoutput><a
    href='#CGI.SCRIPT_NAME#?Start=#PageRow#&amp;next=# maxrows#'><cfif #curpage# is
    '#thisPage#'><b><font
    size='2'>#ThisPage#</font></b><cfelse>#ThisPage#</cfif></a></cfoutput> <!---
    Otherwise, show with link so user can go to page ---> <cfelse> <cfoutput> <a
    href='#CGI.SCRIPT_NAME#?Start=#PageRow#&amp;next=# maxrows#'><cfif #curpage# is
    '#thisPage#'><b><font
    size='2'>#ThisPage#</font></b><cfelse>#ThisPage#</cfif></a> </cfoutput> </cfif>
    | <!--- Increment ThisPage variable ---> <cfset thispage = thispage + 1>
    </cfloop> <cfif NextStart LTE getStuff.RecordCount> <cfoutput><A
    HREF='#CGI.SCRIPT_NAME#?start=#nextstart#&amp;next =#maxrows#'>Next
    &amp;gt;&amp;gt;</a></cfoutput> <cfelse> Next &amp;gt;&amp;gt; </cfif>

    gendrall Guest

  2. Similar Questions and Discussions

    1. Navigation on detail page. Please help
      I have created a master page that is for my picture gallery I am using the thumbnail as a link to my detail page. On my detail page I am showing...
    2. Adding Navigation to the Details Page
      Hi, Could someone help, i am wanting to add navigation to my details page to prevent the user from having to move backwards and forwards between...
    3. Recordset page navigation
      Hi , I have a page that get 1000 records and I?m displaying it 10 records a page. I want to use page numbers line 1,2,3, ...as my navigation instead...
    4. Page Navigation?
      how to do this: using "Page numbers" as mode but change the "..." on the buttom of the pages to "previous" and "next". thanks.
    5. Best way to make navigation bar on each page?
      Design your navigation bar, (i think you're working in Dreamweaver) when you finish select it, then make it a Library. Libraries must be inserted...
  3. #2

    Default Re: Page Navigation Help

    I'm not sure what you mean. Do you only want to show 5 pages at most of data
    with 28 records each on them? You could just right right a simple condition
    statement saying if the endrow variable is >= 500 or whatever you want then
    don't show the next or pervious href tags.

    MrDippy Guest

  4. #3

    Default Re: Page Navigation Help

    If I have lots of pages, I dont' want to display 162 page numbers in my page
    nav bar. I would like to be able to display about 10 or so and then giving the
    option to go to the next 10 pages. Sort of the way google does it with only
    showing 19 page numbers.

    gendrall Guest

  5. #4

    Default Re: Page Navigation Help

    okay so you would want your code to look something like this <CFIF TotalRows
    GT 10 AND ShowAllPages IS 'False'> <CFSET TotaRows = 10> </CFIF> <cfloop
    from='1' to='#TotalRows#' step='#RowsPerPage#' index='PageRow'> code to list
    page numbers here <a href='thispage.cfm?showAllPages=true'>Show All Pages</a>
    </CFLOOP> <cfif NextStart LTE getStuff.RecordCount AND (PageRow LTE 10 AND
    ShowAllPages is 'false') > <cfoutput>Next >></cfoutput> <cfelse> Next >> </cfif>

    MrDippy Guest

  6. #5

    Default Re: Page Navigation Help

    Still not working. It didn't do anything to the page numbers except remove all
    put one. I think what I'm going to do is limit the number of results to the
    top 500 in the query and then give the option for a more refined search.

    gendrall Guest

  7. #6

    Default Re: Page Navigation Help

    This is a really good free custom tag that does recordset 'pagination' much
    like you describe. Works like Google's where it limits then number of pages in
    the navigation bar, but as you pan over it gives you more page numbers. I
    modified this one into a CFC for my own use.
    [url]http://www.cornfeed.com/index.cfm/go/products,cfpagelist[/url]

    marmsV4L Guest

  8. #7

    Default Re: Page Navigation Help

    That looks like it could work. Thank you! Much appreciated.

    Sorry for the late response.

    Cheers,
    Rome
    gendrall Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139