1, can realize the function:
Home, last, previous, next, and specify the page jump.
Homepage Last page has the function of automatic hiding.
The Jump Drop-down menu dynamically displays current page numbers and total pages.
2. Principle
Core principles refer to the TRIPDETAIL.CFM page-flipping principle in the compass Travel example included with Codefusion MX. That is to say that the current page is the 6th page, query the database, return number MaxRows set to 1, check the previous page is less than 6 of the number of reverse query, the result is 5,4,3 ..., because only one value is returned, so you get 5. The other is the same.
3, the use of methods
Put the code in the place where you want to implement PageList, replace the cfsnippets,centers and center_id with the lookup, and swap them with the actual database name, table name, and field name.
4. Limitations and deficiencies
Because the CF less than one weeks, CFML is not very familiar with, so some code is still very cumbersome, I think the lack of places are:
(1) style has limitations, because the use of form form, so you can only use a button or picture to display, can not use simple text.
(2) The modification must also be replaced with a lookup. It was only possible to change the three variables defined in the previous database, but later found that the result of using the query in <cfout> would have to be a certain value, such as #gotopage.currentrow#, without the use of dynamic parameters inside. Does the master have any good solution?
<!---database definition--->
<cfset databasename= "cfsnippets" ><!---database name--->
<cfset tablename= "Centers" ><!---table Name--->
<cfset targetname= "center_id" ><!---field name (generally ID), define here and replace all gotopage.center_id center_id--->
<!---handle Jump Action--->
<cfif isdefined ("Form.recordid") ><!---to determine whether there is a jump request--->
<cfquery name= "Pagequery" datasource= "#databasename #" maxrows= "1" >
SELECT #targetname # from #tablename #
<cfif isdefined ("Form.btnprev") ><!---previous page number--->
WHERE #targetname # < #Form. recordid#
ORDER BY #targetname # DESC
<cfelseif isdefined ("Form.btnnext") ><!---back page number--->
WHERE #targetname # > #Form. recordid#
ORDER BY #targetname #
<cfelseif isdefined ("Form.btnfirst") ><!---home page Number--->
ORDER BY #targetname #
<cfelseif isdefined ("Form.btnlast") ><!---last page number--->
WHERE #targetname # > #Form. recordid#
ORDER BY #targetname # DESC
<cfelseif isdefined ("Form.goto") ><!---Specify page number--->
WHERE #targetname # = #Form. goto#
</cfif>
</cfquery>
<cfif Pagequery.recordcount is 1>
<cflocation url= "#cgi. script_name#?id= #pageQuery. center_id# "><!---Jump--->
<cfelse>
<cflocation url= "#cgi. Script_name#?id= #page. recordid# ">
</cfif>
</cfif>
<!---get the ID of the first page and the last page--->
<cfquery name= "GoToPage" datasource= "#databasename #" >
SELECT #targetname # from #tablename #
</cfquery>
<cfoutput query= "GoToPage" >
<cfif Gotopage.currentrow is 1>
<cfset firstid=gotopage.center_id><!---Home ID--->
<cfelseif Gotopage.currentrow is gotopage.recordcount>
<cfset lastid=gotopage.center_id><!---last ID--->
</cfif>
</cfoutput>
<!---get the ID for this page, such as no pass, default homepage ID--->
<cfif isdefined ("Url.id") >
<cfset pageid=url.id>
<cfelse>
<cfset pageid=firstid>
</cfif>
<!---The main part of the page--->
<form action= "#cgi. script_name# "method=" POST ">
<input type= "hidden" name= "RecordID" value= "<cfoutput> #pageid #</cfoutput>" ><!---hidden field transfer this page ID-- ->
Later found that something was wrong, and modified:
The above code can only be used to list page with only one record per page, and if a page has more than one record, the above method will not work.
Here's what I've done to modify the code, can implement a page to put more than one record, each page put how many records can be defined in the Pagerow, in addition also do not need to find replacement to change, as long as the initialization of the four parameters of the relevant content on the line, other places do not need to change.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.