have anyone ever creates navigation buttons such as next,previous in coldfusion?

can i see ours if you have created one?

Based on query data? If so yes, but I don't have it with me at the moment. I'll get back to you.

ya its based on query.
so thanks in advance..;)

Are you permitted by your hosting company to use custom tags?

ya am permitted

OK. I have a custom tag that will pretty much do everything for you. I'll post it in the morning when I get back to work.

Here goes. There's a lot here, so bear with me. This is actually two custom tags. One to set the variables and one to create the links.

Here is the first custom tag:

<!--- pageNumSetup.cfm --->

<cfscript>
	// round page number variable up
	function roundPageNum(number) {
		
		var x = 0;
		
		x = Int(number);
		
		if(number - x neq 0) {
			x = x + 1;
		}
		
		return x;
	}
</cfscript>

<!--- Set Default values --->
<cfparam name="Caller.startRow" default="1">
<cfparam name="Caller.nextPage" default="">
<cfparam name="Caller.prevPage" default="">
<cfparam name="Caller.numPerPage" default="20">
<cfparam name="Caller.numPages" default="0">
<cfparam name="Caller.curPage" default="1">
<cfparam name="Attributes.queryName" default="">

<!--- Set values for previous and next pages --->
<cfset Caller.nextPage = Caller.startRow + Caller.numPerPage>
<cfset Caller.prevPage = Caller.startRow - Caller.numPerPage>

<!--- Determine the total number of pages for this search --->
<cfset Caller.numPages = Attributes.queryName.RecordCount / Caller.numPerPage >
<cfset Caller.numPages = roundPageNum(Caller.numPages)>
<cfset Caller.curPage = ((Caller.startrow -1) / Caller.numPerPage) + 1>

Now for the navigation links:

<!--- pageNum.cfm --->

<!--- Set Default values --->
<cfparam name="Caller.startRow" default=""> <!--- Numeric --->
<cfparam name="Caller.nextPage" default=""> <!--- Numeric --->
<cfparam name="Caller.prevPage" default=""> <!--- Numeric --->
<cfparam name="Caller.numPerPage" default="20"> <!--- Numeric --->
<cfparam name="Caller.numPages" default=""> <!--- Numeric --->
<cfparam name="Caller.curPage" default=""> <!--- Numeric --->
<cfparam name="Caller.queryName" default=""> <!--- Query --->
<cfparam name="Attributes.forwardImage" default=""> <!--- string --->
<cfparam name="Attributes.backImage" default=""> <!--- string --->

<!--- This variable is used to direct the links to the correct template --->
<cfparam name="Attributes.pageName" default="Index.cfm">  <!--- string --->

<!--- If there is only one page of results, there is no need to show links --->
<cfif Attributes.queryName.RecordCount LT Attributes.numPerPage>
	<span class="curPage">Page 1 of 1</span>
<cfelse>

	<cfoutput>

		<!--- If this is not the first page, show a link to the previous --->
		<cfif Attributes.prevPage gt 0>
			<a href="#Attributes.pageName#?startrow=#Attributes.prevPage#" class="pageNum"><cfif Attributes.backImage neq ""><img src="#Attributes.backImage#" border="0" /><cfelse>&lt;&lt;Previous Page</cfif></a>&nbsp;&nbsp;
		</cfif>
		
        <!--- If this is the first page, show the page number without a link --->
		<cfif Attributes.curPage eq 1>
			<span class="curPage">1</span>
		<cfelse>
			<a href="#Attributes.pageName#?startRow=1" class="pageNum">1</a>
		</cfif>
		
        <!--- Loop through the number of pages and create the links --->
		<cfloop index="LoopCount" from="2" to="#Attributes.numPages#">
		
        	<!--- If the loopcount is the current page, show the page number without a link --->
			<cfif LoopCount eq Attributes.curPage>
				<span class="curPage">#LoopCount#</span>
			<cfelse>
				<cfset pageStart = ((LoopCount - 1 ) * Attributes.numPerPage) + 1>
				<a href="#Attributes.pageName#?startRow=#pageStart#" class="pageNum">#LoopCount#</a>
			</cfif>
		
		</cfloop>
		
        <!--- If we are not on the last page, show a next button --->
		<cfif Attributes.nextPage lte Attributes.queryName.RecordCount>
			&nbsp;&nbsp;<a href="#Attributes.pageName#?startRow=#Attributes.nextPage#" class="pageNum"><cfif Attributes.forwardImage neq ""><img src="#Attributes.forwardImage#" border="0" /><cfelse>Next Page&gt;&gt;</cfif></a>
		</cfif>
		
	</cfoutput>
</cfif>

So, how do you use it? Like this:

<!--- Set Default values --->
<cfparam name="startRow" default="1">
<cfparam name="nextPage" default="">
<cfparam name="prevPage" default="">
<cfparam name="numPerPage" default="20">
<cfparam name="numPages" default="0">
<cfparam name="curPage" default="1">

<cf_pageNumSetup queryName="qryQuery" />

<cf_pageNum forwardImage="next.gif" backImage="previous.gif" pageName="Index.cfm" />

Let me know how that works for you...

hiiii
ya the navigation button works correctly and perfectly.
thnk

Anytime. Glad to help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.