Coldfusion MX pagelist Rookie Edition tutorial _coldfusion

Source: Internet
Author: User
Tags goto prev
Originally written:

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-- ->

<!--home/prev-->
<cfif PageID NEQ firstid>
<input type= "Submit" Name= "Btnfirst" value= "Home" >
<input type= "Submit" Name= "Btnprev" value= "prev" >
</cfif>

<!--pages, jump-->
<B> jump to: </B> <select name= "goto" >
<cfoutput query= "GoToPage" >
<cfif gotopage.center_id is pageid>
<option value= "#gotopage. center_id#" selected> #gotopage .currentrow#<!---The number of this page is selected--->
<cfelse>
<option value= "#gotopage. center_id#" > #gotopage. currentrow#
</cfif>
</cfoutput>
</option></select>/<cfoutput > #gotopage .recordcount#</cfoutput> page
<input name= "Go" type= "submit" value= "Go" >

<!--last/next page-->
<cfif PageID NEQ lastid>
<input type= "Submit" Name= "Btnnext" value= "next Page" >
<input type= "Submit" Name= "Btnlast" value= "Last" >
</cfif>
</form>


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 code is a lot simpler than it used to be:)


<!---initialization--->
<cfset databasename= "cfsnippets" ><!---database name--->
<cfset tablename= "Centers" ><!---table Name--->
<cfset targetname= "center_id" ><!---field name (typically ID)--->
<cfset pagerow=1><!---records per page--->
<!---handle Jump Action--->
<cfif isdefined ("Form.thispage") ><!---to determine whether there is a jump request--->
<cfif isdefined ("Form.btnprev") ><!---previous page number--->
<cfset pagequery= #Form .thispage#-1>
<cfelseif isdefined ("Form.btnnext") ><!---back page number--->
<cfset pagequery= #Form .thispage#+1>
<cfelseif isdefined ("Form.btnfirst") ><!---home page Number--->
<cfset pagequery=1>
<cfelseif isdefined ("Form.btnlast") ><!---last page number--->
<cfset pagequery= #Form .lastpage#>
<cfelseif isdefined ("Form.goto") ><!---Specify page number--->
<cfset pagequery= #Form .goto#>
</cfif>
<cflocation url= "#cgi. script_name#?page= #pageQuery # "><!---Jump--->
</cfif>
<!---get last page number--->
<cfquery name= "GoToPage" datasource= "#databasename #" >
SELECT #targetname # from #tablename #
</cfquery>
<cfset lastpage= #gotopage .recordcount#\pagerow><!---last page number--->
<!---get page number, if not passed, default is 1--->
<cfif isdefined ("Url.page") >
<cfset pageid=url.page>
<cfelse>
<cfset pageid=1>
</cfif>
<!---The main part of the page--->
<form action= "" method= "POST" >
<input type= "hidden" name= "Thispage" value= "<cfoutput> #pageid #</cfoutput>" ><!---hidden field transfer this page ID-- ->
<input type= "hidden" name= "LastPage" value= "<cfoutput> #lastpage #</cfoutput>" ><!---hidden field transfer last page number --->
<!--home/prev-->
<cfif PageID NEQ 1>
<input type= "Submit" Name= "Btnfirst" value= "Home" >
<input type= "Submit" Name= "Btnprev" value= "prev" >
</cfif>
<!--pages, jump-->
<B> jump to: </B> <select name= "goto" >
<cfloop index= "PageNumber" from= "1" to= "#lastpage #" >
<cfoutput>
<cfif #pagenumber # is pageid>
<option value= "#pagenumber #" selected> #pagenumber #<!---The number of this page is selected--->
<cfelse>
<option value= "#pagenumber #" > #pagenumber #
</cfif>
</cfoutput>
</cfloop>
</option></select>/<cfoutput > #lastpage #</cfoutput> page
<input name= "Go" type= "submit" value= "Go" >
<!--last/next page-->
<cfif PageID NEQ lastpage>
<input type= "Submit" Name= "Btnnext" value= "next Page" >
<input type= "Submit" Name= "Btnlast" value= "Last" >
</cfif>
</form>


Oh, a rookie version of the PageList finally completed, very simple, using the method is also very stupid.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.