Originally written:
1. Functions that can be realized:
Home page, last page, previous page, next page and specified page jump.
The last page of the home page has the function of automatically hiding.
The jump drop-down menu dynamically displays the current page number and total page count.
2. Principle
The core principle refers to the page turning principle in the Compass Travel example included with Codefusion MX. That is, if the current page is page 6, query the database, and the return number maxRows is set to 1. Looking up the previous page is to query the numbers less than 6 in reverse order. The result is 5, 4, 3..., because only one value is returned, so 5 is obtained. The same goes for others.
3. How to use
Put the code into the place where you want to implement pagelist, modify the cfsnippets, centers and center_IDs in it with search replacement, and replace them with the actual database name, table name and field name.
4. Limitations and Deficiencies
Because I have been learning CF for less than a week and am not very familiar with CFml, some codes are still very cumbersome. What I think are insufficient are:
(1) The style has limitations, because it uses form form, so it can only be displayed with buttons or pictures, and cannot be used with simple text.
(2) Modification must also be replaced by search. It was originally planned to change only the three variables defined in the previous database, but later I found that the result of using the query in <cfout> must be a determined value, such as ##, and no longer use dynamic parameters. What are the good solutions for experts?
<!--- Database definition -->
<cfset databasename="cfsnippets"><!--- Database name -->
<cfset tablename="centers"><!--- Table name -->
<cfset targetname="center_ID"><!--- field name (usually ID). While defining this, you must also replace the center_ID in gotopage.center_ID with search. --->
<!--- Processing jump action --->
<cfif IsDefined("")><!--- Judge whether there is a jump request -->
<cfquery name="pageQuery" datasource="#databasename#" maxrows="1">
SELECT #targetname# FROM #tablename#
<cfif IsDefined("")><!--- Previous page number -->
WHERE #targetname# < ##
ORDER BY #targetname# DESC
<cfelseif IsDefined("")><!--- The next page number -->
WHERE #targetname# > ##
ORDER BY #targetname#
<cfelseif IsDefined("")><!--- Homepage Number -->
ORDER BY #targetname#
<cfelseif IsDefined("")><!--- Last Page Number -->
WHERE #targetname# > ##
ORDER BY #targetname# DESC
<cfelseif IsDefined("")><!--- Specify page number -->
WHERE #targetname# = ##
</cfif>
</cfquery>
<cfif is 1>
<cflocation url="#cgi.SCRIPT_NAME#?ID=#pageQuery.center_ID#"><!--- Jump -->
<cfelse>
<cflocation url="#cgi.SCRIPT_NAME#?ID=##">
</cfif>
</cfif>
<!--- Get the ID corresponding to the homepage and the last page -->
<cfquery name="gotopage" datasource="#databasename#" >
SELECT #targetname# FROM #tablename#
</cfquery>
<cfoutput query="gotopage">
<cfif is 1>
<cfset firstid=gotopage.center_ID><!--- The ID corresponding to the home page -->
<cfelseif is >
<cfset lastid=gotopage.center_ID><!--- The ID corresponding to the last page -->
</cfif>
</cfoutput>
<!--- Get the ID corresponding to this page. If it is not passed, the default is the homepage ID --->
<cfif isdefined("")>
<cfset pageid=>
<cfelse>
<cfset pageid=firstid>
</cfif>
<!--- The main part of the page turn -->
<form action="#cgi.SCRIPT_NAME#" method="post">
<input type="hidden" name="RecordID" value="<cfoutput>#pageid#</cfoutput>"><!---- Hidden fields to transmit this page ID --->
<!-- Home/Previous Page-->
<cfif pageid neq firstid>
<input type="submit" name="btnFirst" value="Home">
<input type="submit" name="btnPrev" value="Previous page">
</cfif>
<!-- Number of pages, jump-->
<B>Skip to:</B>Lead <select name="goto">
<cfoutput query="gotopage">
<cfif gotopage.center_ID is pageid>
<option value="#gotopage.center_ID#" selected>##<!--- Make the number on this page in the selected state -->
<cfelse>
<option value="#gotopage.center_ID#">##
</cfif>
</cfoutput>
</option></select>/<cfoutput >##</cfoutput> Page
<input name="Go" type="submit" value="GO">
<!-- Last page/next page-->
<cfif pageid neq lastid>
<input type="submit" name="btnNext" value="next">
<input type="submit" name="btnLast" value="last page">
</cfif>
</form>
Later, I found something was wrong and made changes:
The above code can only be used to list pages with only one record per page. If there are multiple records on a page, the above method will not work.
Below is the code I have modified, which can implement multiple records on a page. How many records can be placed on each page can be defined in pagerow. In addition, there is no need to change it by searching and replacing it. Just set the four parameters in the initialization as your own related content, and there is no need to change it elsewhere.
The code is much simpler than the original one :)
<!--- Initialization -->
<cfset databasename="cfsnippets"><!--- Database name -->
<cfset tablename="centers"><!--- Table name -->
<cfset targetname="center_ID"><!--- field name (usually ID) -->
<cfset pagerow=1><!--- Number of records per page -->
<!--- Processing jump action --->
<cfif IsDefined("")><!---
<cfif IsDefined("")><!--- Previous page number -->
<cfset pageQuery=##-1>
<cfelseif IsDefined("")><!--- The next page number -->
<cfset pageQuery=##+1>
<cfelseif IsDefined("")><!--- Homepage Number -->
<cfset pageQuery=1>
<cfelseif IsDefined("")><!--- Last Page Number -->
<cfset pageQuery=##>
<cfelseif IsDefined("")><!--- Specify page number -->
<cfset pageQuery=##>
</cfif>
<cflocation url="#cgi.SCRIPT_NAME#?page=#pageQuery#"><!--- Jump -->
</cfif>
<!--- Get the last page number --->
<cfquery name="gotopage" datasource="#databasename#" >
SELECT #targetname# FROM #tablename#
</cfquery>
<cfset lastpage=##\pagerow><!--- Lastpage number -->
<!--- Get the page number of this page. If there is no transmission, the default is 1 -->
<cfif isdefined("")>
<cfset pageid=>
<cfelse>
<cfset pageid=1>
</cfif>
<!--- The main part of the page turn -->
<form action="" method="post">
<input type="hidden" name="thispage" value="<cfoutput>#pageid#</cfoutput>"><!---- Hidden field to transmit this page ID -->
<input type="hidden" name="lastpage" value="<cfoutput>#lastpage#</cfoutput>"><!---- Hidden field transfer last page number -->
<!-- Home/Previous Page-->
<cfif pageid neq 1>
<input type="submit" name="btnFirst" value="Home">
<input type="submit" name="btnPrev" value="Previous page">
</cfif>
<!-- Number of pages, jump-->
<B>Skip to:</B>Lead <select name="goto">
<cfloop index="pagenumber" from="1" to="#lastpage#">
<cfoutput>
<cfif #pagenumber# is pageid>
<option value="#pagenumber#" selected>#pagenumber#<!---- Make the number on this page in the selected state -->
<cfelse>
<option value="#pagenumber#">#pagenumber#
</cfif>
</cfoutput>
</cfloop>
</option></select>/<cfoutput >#lastpage#</cfoutput> Page
<input name="Go" type="submit" value="GO">
<!-- Last page/next page-->
<cfif pageid neq lastpage>
<input type="submit" name="btnNext" value="next">
<input type="submit" name="btnLast" value="last page">
</cfif>
</form>
Haha, a rookie version of the pagelist has finally been completed. It is very simple and the method used is quite stupid.
1. Functions that can be realized:
Home page, last page, previous page, next page and specified page jump.
The last page of the home page has the function of automatically hiding.
The jump drop-down menu dynamically displays the current page number and total page count.
2. Principle
The core principle refers to the page turning principle in the Compass Travel example included with Codefusion MX. That is, if the current page is page 6, query the database, and the return number maxRows is set to 1. Looking up the previous page is to query the numbers less than 6 in reverse order. The result is 5, 4, 3..., because only one value is returned, so 5 is obtained. The same goes for others.
3. How to use
Put the code into the place where you want to implement pagelist, modify the cfsnippets, centers and center_IDs in it with search replacement, and replace them with the actual database name, table name and field name.
4. Limitations and Deficiencies
Because I have been learning CF for less than a week and am not very familiar with CFml, some codes are still very cumbersome. What I think are insufficient are:
(1) The style has limitations, because it uses form form, so it can only be displayed with buttons or pictures, and cannot be used with simple text.
(2) Modification must also be replaced by search. It was originally planned to change only the three variables defined in the previous database, but later I found that the result of using the query in <cfout> must be a determined value, such as ##, and no longer use dynamic parameters. What are the good solutions for experts?
<!--- Database definition -->
<cfset databasename="cfsnippets"><!--- Database name -->
<cfset tablename="centers"><!--- Table name -->
<cfset targetname="center_ID"><!--- field name (usually ID). While defining this, you must also replace the center_ID in gotopage.center_ID with search. --->
<!--- Processing jump action --->
<cfif IsDefined("")><!--- Judge whether there is a jump request -->
<cfquery name="pageQuery" datasource="#databasename#" maxrows="1">
SELECT #targetname# FROM #tablename#
<cfif IsDefined("")><!--- Previous page number -->
WHERE #targetname# < ##
ORDER BY #targetname# DESC
<cfelseif IsDefined("")><!--- The next page number -->
WHERE #targetname# > ##
ORDER BY #targetname#
<cfelseif IsDefined("")><!--- Homepage Number -->
ORDER BY #targetname#
<cfelseif IsDefined("")><!--- Last Page Number -->
WHERE #targetname# > ##
ORDER BY #targetname# DESC
<cfelseif IsDefined("")><!--- Specify page number -->
WHERE #targetname# = ##
</cfif>
</cfquery>
<cfif is 1>
<cflocation url="#cgi.SCRIPT_NAME#?ID=#pageQuery.center_ID#"><!--- Jump -->
<cfelse>
<cflocation url="#cgi.SCRIPT_NAME#?ID=##">
</cfif>
</cfif>
<!--- Get the ID corresponding to the homepage and the last page -->
<cfquery name="gotopage" datasource="#databasename#" >
SELECT #targetname# FROM #tablename#
</cfquery>
<cfoutput query="gotopage">
<cfif is 1>
<cfset firstid=gotopage.center_ID><!--- The ID corresponding to the home page -->
<cfelseif is >
<cfset lastid=gotopage.center_ID><!--- The ID corresponding to the last page -->
</cfif>
</cfoutput>
<!--- Get the ID corresponding to this page. If it is not passed, the default is the homepage ID --->
<cfif isdefined("")>
<cfset pageid=>
<cfelse>
<cfset pageid=firstid>
</cfif>
<!--- The main part of the page turn -->
<form action="#cgi.SCRIPT_NAME#" method="post">
<input type="hidden" name="RecordID" value="<cfoutput>#pageid#</cfoutput>"><!---- Hidden fields to transmit this page ID --->
<!-- Home/Previous Page-->
<cfif pageid neq firstid>
<input type="submit" name="btnFirst" value="Home">
<input type="submit" name="btnPrev" value="Previous page">
</cfif>
<!-- Number of pages, jump-->
<B>Skip to:</B>Lead <select name="goto">
<cfoutput query="gotopage">
<cfif gotopage.center_ID is pageid>
<option value="#gotopage.center_ID#" selected>##<!--- Make the number on this page in the selected state -->
<cfelse>
<option value="#gotopage.center_ID#">##
</cfif>
</cfoutput>
</option></select>/<cfoutput >##</cfoutput> Page
<input name="Go" type="submit" value="GO">
<!-- Last page/next page-->
<cfif pageid neq lastid>
<input type="submit" name="btnNext" value="next">
<input type="submit" name="btnLast" value="last page">
</cfif>
</form>
Later, I found something was wrong and made changes:
The above code can only be used to list pages with only one record per page. If there are multiple records on a page, the above method will not work.
Below is the code I have modified, which can implement multiple records on a page. How many records can be placed on each page can be defined in pagerow. In addition, there is no need to change it by searching and replacing it. Just set the four parameters in the initialization as your own related content, and there is no need to change it elsewhere.
The code is much simpler than the original one :)
<!--- Initialization -->
<cfset databasename="cfsnippets"><!--- Database name -->
<cfset tablename="centers"><!--- Table name -->
<cfset targetname="center_ID"><!--- field name (usually ID) -->
<cfset pagerow=1><!--- Number of records per page -->
<!--- Processing jump action --->
<cfif IsDefined("")><!---
<cfif IsDefined("")><!--- Previous page number -->
<cfset pageQuery=##-1>
<cfelseif IsDefined("")><!--- The next page number -->
<cfset pageQuery=##+1>
<cfelseif IsDefined("")><!--- Homepage Number -->
<cfset pageQuery=1>
<cfelseif IsDefined("")><!--- Last Page Number -->
<cfset pageQuery=##>
<cfelseif IsDefined("")><!--- Specify page number -->
<cfset pageQuery=##>
</cfif>
<cflocation url="#cgi.SCRIPT_NAME#?page=#pageQuery#"><!--- Jump -->
</cfif>
<!--- Get the last page number --->
<cfquery name="gotopage" datasource="#databasename#" >
SELECT #targetname# FROM #tablename#
</cfquery>
<cfset lastpage=##\pagerow><!--- Lastpage number -->
<!--- Get the page number of this page. If there is no transmission, the default is 1 -->
<cfif isdefined("")>
<cfset pageid=>
<cfelse>
<cfset pageid=1>
</cfif>
<!--- The main part of the page turn -->
<form action="" method="post">
<input type="hidden" name="thispage" value="<cfoutput>#pageid#</cfoutput>"><!---- Hidden field to transmit this page ID -->
<input type="hidden" name="lastpage" value="<cfoutput>#lastpage#</cfoutput>"><!---- Hidden field transfer last page number -->
<!-- Home/Previous Page-->
<cfif pageid neq 1>
<input type="submit" name="btnFirst" value="Home">
<input type="submit" name="btnPrev" value="Previous page">
</cfif>
<!-- Number of pages, jump-->
<B>Skip to:</B>Lead <select name="goto">
<cfloop index="pagenumber" from="1" to="#lastpage#">
<cfoutput>
<cfif #pagenumber# is pageid>
<option value="#pagenumber#" selected>#pagenumber#<!---- Make the number on this page in the selected state -->
<cfelse>
<option value="#pagenumber#">#pagenumber#
</cfif>
</cfoutput>
</cfloop>
</option></select>/<cfoutput >#lastpage#</cfoutput> Page
<input name="Go" type="submit" value="GO">
<!-- Last page/next page-->
<cfif pageid neq lastpage>
<input type="submit" name="btnNext" value="next">
<input type="submit" name="btnLast" value="last page">
</cfif>
</form>
Haha, a rookie version of the pagelist has finally been completed. It is very simple and the method used is quite stupid.