Skip to main content
Jun 29, 2011 9:20 PM UTC
Question

Help limiting page totals in pagination code

HI ,

I have been trying to limit the output of page totals in my pagination code so I can use it at the top of the page. I grabbed the existing code from a tutorial and it works fine. I tried simply settting a page total variable and outputting , but I do realize it's a little ore compicated than that. Any help will be greatly appreciated.

<div style="padding-top:10px;">
<p> </p>
</div>
<p align="center" class="breadcrumb">


Top of page setting some vars :

<!--- set up pagination --->
<cfset perpage=12>
<cfparam name="url.start" default="1">

  <cfif not isNumeric(url.start) or url.start lt 1 or url.start gt qry_prod.recordCount or round(url.start) neq url.start>
    <cfset url.start = 1>
  </cfif>

<!--- outputting  query reslults table rows of product stuff with maxrows set to perpage var--->

      <table>

          <tr>

               <td> ect ...........................

<!--- Here I employ the pageination code , displays at bottom of page --- >


[
  <cfif url.start gt 1>
      <cfset link = cgi.script_name & "?fuseaction=products&action=cat&id=#url.id#&start=" & (url.start - perpage)>
      <cfoutput><a href="#link#">Previous Page</a></cfoutput>
  <cfelse>
      Previous Page
  </cfif>
  |
      
      <!--- Start Page Number --->

    <cfset pageCount = 1>
    <cfset pageLink = 1>    
    <cfset totalPages = Ceiling(qry_prod.recordCount / perpage)>

    <cfloop index="c" from="1" to="#totalPages#">
      <cfoutput>
      <a href="?fuseaction=products&action=cat&id=#url.id#&start=#pageLink#">#pageCount#</a>
     </cfoutput>
    
     <cfset pageCount = pageCount + 1>
    
    <cfset pageLink = pageLink + perpage>
    
    </cfloop>
    |
    <!--- End Page Number --->
   
   
  <cfif (url.start + perpage - 1) lt qry_prod.recordCount>
      <cfset link = cgi.script_name & "?fuseaction=products&action=cat&id=#url.id#&start=" & (url.start + perpage)>
      <cfoutput><a href="#link#">Next Page</a></cfoutput>
  <cfelse>
      Next Page
  </cfif>
  ]
  </p>

Thanks ,

Steve

    This topic is closed to new replies. Start a new post to keep the conversation going.

    7 replies

    Jun 30, 2011 4:29 PM UTC

    Thanks ... easy to implement. Works great!

    Translate
    Inspiring
    Jan 30, 2018 7:55 PM UTC

    Steevo2,

        How did you implement the Google style into your code above? Could you post your updated code? Thanks.

    Andy

    Translate
    Inspiring
    Jun 29, 2011 9:39 PM UTC

    Despite reading it twice, I still do not understand the question ;-)  What is the code doing wrong, and what do you want it to do instead?

    Translate
    Jun 29, 2011 9:47 PM UTC

    The code isn't doing anything wrong. I simply wish to append the functionality by limiting the pageCount output so that if a have 40 ,50 even 100 total pages, they won't spread acroos the page. Sounds simple enough , but I am kinda stumped.

    Translate
    Inspiring
    Jun 29, 2011 10:00 PM UTC
       The code isn't doing anything wrong.

    In your words, wrong is: "the total pages are ... spread acroos the page".  You would like the output to be different (somehow).

    Without actually running your code ... I would guess your results are something like:

                      Page 1, Page 2, Page 3, Page 4, Page N, Page 40

    What do you want to see instead of that?

    Translate