Skip to main content
Known Participant
May 7, 2009
Question

I ask to help on pagination

  • May 7, 2009
  • 1 reply
  • 914 views

I ask to help on pagination

All greetings! For me a question on pagination

Has made pagination for the directory of articles on a site, but at addition of new articles in a database, having divided into pages proceeds in a format

BACK 1 2 3 4 5 6 7 8 NEXT

So can proceed indefinitely (to 100-200 pages etc.).

I wish to make, that pagination was in such format:

BACK 1 2 3 4 5 6 7 8 9 10... NEXT

That is, that pages were displayed to 10, and the others were not displayed, and began to be displayed, when the user has reached 10 pages, for example:

BACK... 11 12 13 14 15 16 17 18 19 20 NEXT

CODE:

<cfquery name="getArticle" datasource="Article" result="resultInfo">

SELECT Articles.Id, Articles.title, Articles.anonce, Articles.disc, Articles.add_date, Articles.image, Articles.tag

FROM Articles

</cfquery>

<!--- set how many records you want to display per page --->

<cfset Result_Per_Page="1">

<!--- get the total record count from q_fetch query --->

<cfset Total_Records="#getArticle.recordcount#">

<!--- set the default value for the offset record set number --->

<cfparam name="URL.offset" default="0">

<!--- the limit result set(i.e., end row) --->

<cfset limit=URL.offset+Result_Per_Page>

<!--- page results start from? --->

<cfset start_result=URL.offset+1>

<!--- make sure that the initial start row is starting from 1 --->

<cfset URL.offset=URL.offset+1>

<!--- if the record is their more than one page so show the navigation bar --->

<cfif Total_Records GT Result_Per_Page>

<br>

<!--- Create Previous Link --->

<cfif URL.offset GT Result_Per_Page>

<!--- Previous Link Offset --->

<cfset prev_link=URL.offset-Result_Per_Page-1>

<cfoutput><b class="numpage_link"><a href="#cgi.script_name#?offset=#prev_link#">BACK</a></b></cfoutput>

</cfif>

<!--- Find out how many pages are there for display  --->

<cfset Total_Pages=ceiling(Total_Records/Result_Per_Page)>

<!--- now loop it for navigation page numbers --->

<cfloop index="i" from="1" to="#Total_Pages#">

<cfset j=i-1>

<!--- create offset value for page numbers --->

<cfset offsetvalue=j*Result_Per_Page>

<!--- deactivate the link if the page number is current page --->

<cfif offset_value EQ URL.offset-1 >

<cfoutput><b class="numpage">#i#</b></cfoutput>

<cfelse>

<cfoutput><b class="numpage_link"><a href="#cgi.script_name#?offset=#offset_value#">#i#</a></b></cfoutput>

</cfif>

</cfloop>

<!--- create Next Link --->

<cfif limit LT Total_Records>

<!--- Next Link Offset --->

<cfset next_link=URL.offset+Result_Per_Page-1>

<cfoutput><b class="numpage_link"><a href="#cgi.script_name#?offset=#next_link#">NEXT</a></b></cfoutput>

</cfif>

</cfif>

<!--- display the result on the screen --->

<cfloop query="getArticle" startrow="#URL.offset#" endrow="#limit#">

<cfoutput>

<div class="center_item_line">

<h4>#DateFormat(Now())# <p>#getArticle.tag# </p></h4>

<div class=center_item_img><a href="article.cfm?ID=#getArticle.Id#"><img src="../images/#getArticle.image#" width="180" height="133" alt="Новости зарубежной недвижимости"></a></div>

<h4><a href="article.cfm?ID=#getArticle.Id#">#getArticle.title#</a></h4>

<p>#getArticle.anonce# </p>

<div style='clear:both;'></div>

<br/>

<div class="line"></div>

</div>

</cfoutput> <br>

</cfloop>

</body>

This topic has been closed for replies.

1 reply

Inspiring
May 8, 2009

You might want to take a look at the PaginationCFC project at RIAForge.com:

http://paginationcfc.riaforge.org/

It looks like a very useful pagination library that could help you manage your large data set output.