• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help limiting page totals in pagination code

Guest
Jun 29, 2011 Jun 29, 2011

Copy link to clipboard

Copied

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

Views

976

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 29, 2011 Jun 29, 2011

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 29, 2011 Jun 29, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 29, 2011 Jun 29, 2011

Copy link to clipboard

Copied

   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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 29, 2011 Jun 29, 2011

Copy link to clipboard

Copied

As of now it renders :

[ Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | Next Page ]

I would like to limit the output of page numbers ,say to 5 ,  while still being able to click though all of them. Tks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 29, 2011 Jun 29, 2011

Copy link to clipboard

Copied

Ah, thanks. Have a look at http://paginationcfc.riaforge.org/. As you can see in the demo url, selecting the "google" style lets you implement that kind of pagination.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 30, 2011 Jun 30, 2011

Copy link to clipboard

Copied

Thanks ... easy to implement. Works great!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 30, 2018 Jan 30, 2018

Copy link to clipboard

Copied

LATEST

Steevo2,

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

Andy

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation