On 9/29/00, Vincent penned:
> <cfquery name="get_items" datasource="users" maxrows = 10>
> SELECT itemnum
> FROM items
> WHERE user_id = 12345
></cfquery>
>
>Now this will get me the top 10 rows, yes! Now what Im looking at is
>rows 10-20, then 20-30....etc
>
>Is this possible. I know of one way, but its kinda a long cut.
Hi Vin. Maxrows will go in the cfoutput portion of your query.
<cfoutput query="get_items" maxrows="#maxrows#" startrow="#startrow#">
Startrow will be the dynamic variable. On the initial search, you
will pass a value of "1". Or you can pass nothing and use cfparam to
set a default of "1".
<CFPARAM NAME="startrow" DEFAULT="1">
<CFPARAM NAME="maxrows" DEFAULT="10">
Then to do your next and previous buttons, you will generally use 2
forms and place this before them:
<cfset PrevStart = StartRow - MaxRows>
<cfset NextStart = StartRow + MaxRows>
<cfif PrevStart GTE 1>
<form action="samepage.cfm" method="post">
(form stuff)
<input type="hidden" name="startrow" value="#PrevStart#">
<input type="hidden" name="maxrows" value="#maxrows#">
<input type="Submit" value="Previous #maxrows# Records">
</form>
</cfif>
<cfif NextStart LTE Get_Items.RecordCount>
<form action="samepage.cfm" method="post">
(form stuff)
<input type="hidden" name="startrow" value="#NextStart#">
<input type="hidden" name="maxrows" value="#maxrows#">
<input type="Submit" value="Next #maxrows# Records">
</form>
</cfif>
You can also do some neat stuff like checking if there are less than
maxrows records left and show the Next button accordingly.
<cfset remaining = Get_Items.RecordCount - startrow + 1>
This will go AFTER the cfset PrevStart/NextStart code.
In a search returning 28 records, when you return records 11 thru 20,
the value of remaining would be 8.
28 - 21 (the value of startrow) = 7 + 1 = 8
Then you could set accordingly.
<cfif remaining GT maxrows>
<input type="Submit" value="Next #maxrows# Records">
<cfelseif remaining LTE maxrows and remaining GT "1">
<input type="Submit" value="Final #remaining# Records">
<cfelseif remaining is "1">
<input type="Submit" value="Final Record">
</cfif>
You can use the same parameters at the top of the search results:
<CFIF Get_Items.Recordcount IS "1">
Displaying 1 item found
<CFELSE>
Displaying records #startrow# thru
<cfif Get_Items.Recordcount LTE (startrow + maxrows - 1)>
#Get_Items.Recordcount#<cfelse>
#Abs(startrow + maxrows - 1)#</cfif>
of #Get_Items.Recordcount# records found
</CFIF>
HTH
--
Bud Schneehagen - Tropical Web Creations
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
ColdFusion Solutions / eCommerce Development
[EMAIL PROTECTED]
http://www.twcreations.com/
954.721.3452
------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.