Skip to main content
Inspiring
February 1, 2018
Answered

Pagination Links

  • February 1, 2018
  • 1 reply
  • 1857 views

Hi. How are most pagination links set up? Are they dynamic on the same page that just reloads the content from the database? Or are they linked to multiple pages such as page 1, 2, 3, etc. with the list of products or whatever you would have on your page?

This topic has been closed for replies.
Correct answer IronwoodElectronics

From what I can see, your query is getting the top 5 records on every page load, and the output looks like you're showing the top 5 records on every page load.  You should use a conditional to get records starting at a certain point.

I don't know what flavor of SQL you are using, there are different ways of doing it.  Also, I have no idea how your data is aggregated.  If ID is strictly an integer, and increases automatically (ie, 1,2,3,4,5), then it would be simple:

SELECT top 5 names
FROM pages_names 

WHERE ID >= {start row} AND ID <= {end row}

ORDER BY id DESC 

Or some such.

HTH,

^ _ ^


Thanks WolfShade. I finally got this working. Here's my updated working code:

<cfset page_links_shown = 5>

<cfset records_per_page = 5>

<cfset start_record = url.page * records_per_page - records_per_page + 1>

<cfset endrecord=start_record+records_per_page-1>

<cfquery name="get_count" datasource="#application.DataSource#">

SELECT COUNT(id) AS records

FROM pages_names

</cfquery>

<cfquery name="get_names" datasource="#application.DataSource#" result="get_data">

SELECT Press_Date

FROM pages_names

ORDER BY id DESC

</cfquery>

<cfset total_pages = ceiling(get_count.records / records_per_page)>

<cfoutput>

<cfloop query="get_names" startrow="#start_record#" endrow="#endrecord#">

#currentrow#. #Press_Date#<br/>

</cfloop>

<hr>

<cfif url.page EQ 1>

Prev Page

<cfelse>

<a href="pages.cfm?page=#url.page-1#">Prev Page</a>

</cfif>

<hr>

<cfif url.page * records_per_page LT get_count.records>

<a href="pages.cfm?page=#url.page+1#">Next Page</a>

<cfelse>

Next Page

</cfif>

<hr>

<cfparam name="start_page" default="1">

<cfparam name="show_pages" default="#min(page_links_shown,total_pages)#">

<cfif url.page + int(show_pages / 2) - 1 GTE total_pages>

<cfset start_page = total_pages - show_pages + 1>

<cfelseif url.page + 1 GT show_pages>

<cfset start_page = url.page - int(show_pages / 2)>

</cfif>

<cfset end_page = start_page + show_pages - 1>

<cfloop from="#start_page#" to="#end_page#" index="i">

<cfif url.page EQ i>

#i#

<cfelse>

<a href="pages.cfm?page=#i#">#i#</a>

</cfif>

</cfloop>

<hr>

<a href="pages.cfm?page=1">First Page</a>

<hr>

<a href="pages.cfm?page=#total_pages#">Last Page</a>

<hr>

</cfoutput>

1 reply

WolfShade
Legend
February 1, 2018

The first one.

V/r,

^ _ ^

Inspiring
February 1, 2018

Thanks.