Custom Search

Thursday, January 24, 2008

Tutorial : Pagination

hi,
here i introduce pagination technique.this very simple and esay.
this examples first part i only shows how you can make a data show page
with pagination.lets done...

create a page with name pagination.cfm,here the code bellow

pagination.cfm
 <cfparam name="request.dsname" default="suman">
 <cfparam name="TableName" default="admin">
 <cfparam name="MaxRow" default="5">
 <cfparam name="url.PageNumber" default="1">
 
 <cfif NOT IsDefined("session.qSelectQuery") OR IsDefined("url.CreateNewSession")>
  <cfquery name="session.qSelectQuery" datasource="#request.dsname#">
   SELECT *
   FROM #TableName#
  </cfquery>
 </cfif>
 
 <cftable query="session.qSelectQuery" startrow="#((url.PageNumber*MaxRow)-MaxRow)+1#" maxrows="#MaxRow#" colheaders="yes">
  <cfloop list="#session.qSelectQuery.ColumnList#" index="Column">
    <cfcol text="#Evaluate(Column)#" header="#Column#">
  </cfloop>
 </cftable>
 
 <cfoutput>
  <cfloop from="1" to="#Ceiling(session.qSelectQuery.RecordCount/MaxRow)#" index="i">
    <a href="#CGI.SCRIPT_NAME#?PageNumber=#i#">#i#</a>
  </cfloop>
  .........page #url.PageNumber# of #Ceiling(session.qSelectQuery.RecordCount/MaxRow)#......
  <a href="#CGI.SCRIPT_NAME#?CreateNewSession">run the select query again</a>
 </cfoutput>
   
change the parameter as you need.then check with browser.
what you see...yes its done.

for reusable pagination technique read the second part.