Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Database and list only 4 queries per page.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have my query display a list of queries. I would like to only allow 4 per page with a next text link for more then 4.
 
Ok. This is kinda complicated, but if you can figure it out, then go for it.

Save this as a snippet, you will use it a lot, most likely.

Code:
<CFPARAM NAME=&quot;getdata.db_listings_pp&quot; VALUE=&quot;4&quot;>
<!--- The Above Code is needed if you don't have a field in your database named &quot;db_listings_pp&quot;  If you have this value in your DB, it will dynamically figure out how to do the &quot;next&quot; and &quot;previous&quot; things. So, if you don't have that field, you must use this CFPARAM --->

<CFQUERY NAME=&quot;GetData&quot;>
	SELECT *
	FROM 
</CFQUERY>

	<cfparam name=&quot;nextflag&quot; default=&quot;false&quot;>
	<cfparam name=&quot;backflag&quot; default=&quot;false&quot;>
	<cfparam name=&quot;startprod&quot; default=&quot;1&quot;>
	
	<cfset maxrowsnum = #getinfo.db_listings_pp#>
	<cfset endprod = #startprod# + (#getinfo.db_listings_pp# - 1)>
	
		<!--- Deciding weather or not the &quot;next&quot; or &quot;previous&quot; page text should appear by flagging it --->
		<cfif #getdata.recordcount# gt #endprod#>
			<cfset nextflag = &quot;true&quot;>
		</cfif>
		<cfif #startprod# gte (#getinfo.db_listings_pp# + 1)>
			<cfset backflag = &quot;true&quot;>
		</cfif>
		<!--- /deciding... --->

		
		<!--- An output of how many records were returned --->
			<cfoutput>
			<cfif #nextflag# eq &quot;true&quot;>
				<P CLASS=&quot;small&quot;>Showing items #startprod# - #endprod#
			<cfelseif #nextflag# eq &quot;false&quot; AND #backflag# eq &quot;true&quot;>
				<P CLASS=&quot;small&quot;>Showing items #startprod# - #getdata.recordcount#
			<cfelse>
				<P CLASS=&quot;small&quot;>Showing all Items
			</cfif>
			</cfoutput>
		<!--- An Output of how many records were returned --->
<!--- /Figuring Out Stuff --->



<!--- Core Output Of Infro From DB --->
	<TABLE>
	<CFOUTPUT QUERY=&quot;GetData&quot; STARTROW=&quot;#startprod#&quot; MAXROWS=&quot;#maxrowsnum#&quot;>
		<TR>
			<TD bgcolor=&quot;#IIf(CurrentRow mod 2 is 1, DE(&quot;FFFFFF&quot;), DE(&quot;EFEFEF&quot;))#&quot;><P CLASS=&quot;small&quot;>#data#</TD>
		</TR>
	</CFOUTPUT>
	</TABLE>
<!--- /Core Output ... --->



<!--- Next / Previous links --->
	<CFOUTPUT>
		<!--- setting starting points for &quot;next&quot; and &quot;previous&quot; pages --->
		<cfset fwstartnum = #endprod# + 1>
		<cfset bwstartnum = #startprod# - #getinfo.db_listings_pp#>
		<!--- /setting --->
	<P>
	<TABLE BORDER=&quot;0&quot; CELLSPACING=&quot;0&quot; CELLPADDING=&quot;0&quot; WIDTH=&quot;100%&quot;>
		<TR>
			<TD WIDTH=&quot;50%&quot; ALIGN=&quot;LEFT&quot;><P CLASS=&quot;small&quot;>
				<cfif #backflag# eq &quot;true&quot;>
				<A HREF=&quot;page.cfm?page=dsp_db_listing&startprod=#bwstartnum#&quot;>&laquo; Previous Page</A>
				</CFIF>
			</TD>
			<TD WIDTH=&quot;50%&quot; ALIGN=&quot;RIGHT&quot;><P CLASS=&quot;small&quot;>
				<cfif #nextflag# eq &quot;true&quot;>
				<A HREF=&quot;page.cfm?startprod=#fwstartnum#&quot;>Next Page &raquo;</A>
				</CFIF>
			</TD>
		</TR>
	</TABLE>
	</CFOUTPUT>
<!--- /Next / Previous Links--->

- Ryan
 
whoops.

On the top tag, instead of &quot;value=&quot; its &quot;default=&quot;

::was thinkin CFCOOKIE::

Here ya go:

Code:
<CFPARAM NAME=&quot;getdata.db_listings_pp&quot; DEFAULT=&quot;4&quot;>

Sorry.

- Ryan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top