<%
'******************************************************************
' * * * This program name: "Unlimited Flow" paging program
' * * Author: arbiter (AASX)
' * * Version: Million level
'**
' * * qq:22222xx
' * * email:arbiter@21cn.com
' * * http://www.imagecity.org/
'******************************************************************
'**
' * * * the words of the author
'**
' * * Paging program is undoubtedly a lot of network program features a more troublesome thing, in fact, now
' * * Most people still use the traditional paging method (RS.PAGESIZE=XX) to understand
' * * Database operators know that there is a drawback to this traditional approach: the first time you open a page,
' * * It will read all the recordset, which will be fatal when the data is large, and then
' * * The paging speed will also be very slow, very consuming resources. For data above 100,000 orders of magnitude
' * * Library This traditional way of paging has become very weak, let alone millions
' * *). For this reason, I was prompted to do this procedure.
'**
' * * "program features"
'**
' * * Paging operations for large databases with an ideal operational data record of 2 million
' * * within the MAX level version will be unlimited, and no matter how large the database, the page speed is
' * * unchanged), this is the million level paging program in Celeron 1G, memory 512, Win2K ring
' * * Under the test data:
'**
' * * SQL Server 2k + 100,000 records + 20 per page:
' * * Average page speed: 45ms
' * * SQL Server 2k + 1 million records + 20 per page:
' * * Average page speed: 350ms
'**
'**
' * * "paging principle"
'**
' * * * This program no longer uses the rs.pagesize way of paging, connecting the cursor type of the database
' * * Also not use conn,1,x, but conn,0,1, this should be the fastest cursor type, do not
' * * thought it would make the program complex, on the contrary, the program is very simple, if you do not understand,
' * * should be my programming style you're not accustomed to, not program complex.
' * * The center of the "Infinite Stream" pagination is: each page reads only the records that need to be displayed, no longer the traditional
' * * Paging program to read all the data, which is the greatest advantage of this program-less resources, with
' * * speed is also greatly improved, especially in the amount of data, its speed advantage
' * * The more obvious (1 million records are only about 350ms).
' * * * When the program is executed, use the Curcorbegin and Curcorend records to display the first note
' * * record and the ID value of the last record, as the next page turn mark, and then take the top xx
' * * Show the required data, and then record the ID value.
'**
' * * * * words
'**
' * * This procedure is a shared version, provided to the program enthusiasts for research and use, to reprint, spread, repair
' * * To change or for other purposes, please respect the author's hard work, indicate the source.
' * * If there are defects in this program, such as errors, not optimization, please go to www.csdn.net Web development/
' * * ASP column in the discussion, for the development of China's software industry, please do not be complacent:
'**
'********************************************************************
Option Explicit
' Response.Flush
Dim Begintime,endtime
Begintime=timer
Dim Conn,sqlstr,rs,defrecordnum,cursorbegin,cursorend,curpagenum,hav
Defrecordnum=20
'--------------get the relevant parameters----------
If Request ("cursorbegin") = "" Then cursorbegin=0 Else cursorbegin=request ("Cursorbegin")
If Request ("cursorend") = "" Then cursorend=0 Else cursorend=request ("Cursorend")
If Request ("Curpagenum") <> "Then
CURPAGENUM=CLNG (Request ("Curpagenum"))
If curpagenum<=0 Then Curpagenum=1
Else
Curpagenum=1
End If
Hav=request ("hav")
If hav= "" Then hav= "Next"
'----------------End-----------------
'------------display the paging content function--------
Function Turnpagefs (Disprecordnum)
Dim N
While not (rs.eof) and N<disprecordnum
N=n+1
Response.Write "<tr>" &_
"<td bgcolor= ' efefef ' >" &rs (0) & "</td>" &_
"<td bgcolor= ' efefef ' >" &rs (1) & "</td>" &_
"<td bgcolor= ' efefef ' >" &rs (2) & "</td>" &_
"<td bgcolor= ' efefef ' >" &rs (3) & "</td>" &_
"<td bgcolor= ' efefef ' >" &rs (4) & "</td>" &_
"<td bgcolor= ' efefef ' >" &rs (5) & "</td>" &_
"</tr>"
If n=1 Then cursorbegin=rs (0)
If n=defrecordnum or rs.eof Then cursorend=rs (0)
Rs.movenext
Wend
End Function
'-------------connect to the database-------------
Set conn=server.createobject ("Adodb.connection")
' sqlstr= ' Provider=Microsoft.Jet.OLEDB.4.0;Data source= ' &server.mappath ("Mldata.mdb")
Sqlstr= "Driver={sql Server};server=arbiter;uid=arbiter;pwd=123456;database=mldata"
Conn. Open Sqlstr
'---------Total Statistics record/total number of pages---------
'-ps: It is recommended to use COUNT (ID), the ID is AutoNumber and index, otherwise the speed may be greatly compromised
'-ps: This statistic is the most resource-consuming part of this program, and if you cancel this program, it will be about 10 times times faster.
Dim totalrecords,totalpages
Sqlstr= "Select count (ID) as Recordsum from ABC"
Set Rs=conn. Execute (sqlstr,0,1)
Totalrecords=rs ("Recordsum")
Totalpages=abs (Int (totalrecords/defrecordnum* (-1)))
Rs.close
Set rs=nothing
'--------Select the appropriate SQL string according to hav-----
Select case (HAV)
Case "Back"
Cursorend=cursorbegin
sqlstr= "SELECT Top" &DefRecordNum& "_
Id,title,filename,k,imgsize,nameson _
From ABC Where id< "&cursorbegin&_
"and ID in" (Select top) &defrecordnum_
& "ID from ABC Where id<" &cursorbegin_
& Order BY ID DESC
Case "Next"
Sqlstr= "Select Top" &defrecordnum_
& "Id,title,filename,k,imgsize,nameson from ABC Where id>" &cursorend&_
"ORDER by ID"
End Select
Set Rs=conn. Execute (sqlstr,0,1)
%>
<title> "Infinite Flow" pagination program author:arbiter</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<style type= "Text/css" >td,br,div,p,body {font-size:12px}</style>
<body bgcolor= "#FFFFFF" leftmargin= "0" topmargin= "0" >
<table width= "100%" border= "0" cellspacing= "0" cellpadding= "3" bgcolor= "#E2F5FE" >
<TR align= "center" >
<TD colspan= "2" ><%response.write curpagenum& "/" &TotalPages& "page total record number:" &TotalRecords%> </td>
<td><a href= "mllist.asp" > Home </a> <a href=javascript:turnpage (' Back ');> prev </a>
<a href=javascript:turnpage (' Next ');> next page </a> </td>
</tr>
</table>
<table width= "100%" border= "1" cellspacing= "0" cellpadding= "3" bgcolor= "#CCCCCC" >
<tr>
<td>ID</td>
<td>Title</td>
<td>FileName</td>
<td> size </td>
<td> Dimensions </td>
<td> category </td>
</tr>
<%
Turnpagefs (Defrecordnum)
Rs.close
Set rs=nothing
Conn. Close
Set conn=nothing
%>
</table>
<table width= "100%" border= "0" cellspacing= "0" cellpadding= "3" bgcolor= "#E2F5FE" >
<TR align= "center" >
<TD colspan= "2" ><%response.write curpagenum& "/" &TotalPages& "page total record number:" &TotalRecords%> </td>
<td><a href= "mllist.asp" > Home </a> <a href=javascript:turnpage (' Back ');> prev </a>
<a href=javascript:turnpage (' Next ');> next page </a> </td>
</tr>
</table>
<%
Endtime=timer
Response.Write "<br> Program Execution Time:" & (Endtime-begintime) *1000& "MS"
Response.Write "The ID value of the first record (cursorbegin) =" &CursorBegin& "
Response.Write The ID value of the last record (cursorend) = "&CursorEnd& <br><br>"
%>
<script language= "JavaScript" >
function Turnpage (func) {
var curpagenum=<%=curpagenum%>; Get current page number
var cursorbegin=<%=cursorbegin%>; Gets the ID value of the first displayed record
var cursorend=<%=cursorend%>; Gets the ID value of the last displayed record
var totalpages=<%=totalpages%>; Get Total Pages
var backurl= ' mllist.asp? Curpagenum= ' + (CurPageNum-1) + ' &cursorbegin= ' +cursorbegin+ ' &cursorend= ' +cursorend+ ' &hav=back ';
var nexturl= ' mllist.
Asp? Curpagenum= ' + (curpagenum+1) + ' &cursorbegin= ' +cursorbegin+ ' &cursorend= ' +cursorend+ ' &hav=next ';
if (curpagenum<=1 && func== ' back ') {
location.href= ' # ';
}else if (curpagenum>=totalpages && func== ' next ') {
location.href= ' # ';
}else if (func== ' back ') {
Location.href=backurl;
}else if (func= ' next ') {
Location.href=nexturl;
}
}
</script>
</body>
Asp? Curpagenum= ' + (curpagenum+1) + ' &cursorbegin= ' +cursorbegin+ ' &cursorend= ' +cursorend+ ' &hav=next ';
if (curpagenum<=1 && func== ' back ') {
location.href= ' # ';
}else if (curpagenum>=totalpages && func== ' next ') {
location.href= ' # ';
}else if (func== ' back ') {
Location.href=backurl;
}else if (func= ' next ') {
Location.href=nexturl;
}
}
</script>
</body>
Code for Cnbruce:
Pagination sample: [first] [prev] [Next page] [last page] [page: 4/5] [Total 86 pages 20/page] Go: _ Page
The following are common code that must be available.
<%filepath=request.servervariables ("Path_info")%>
<%page=1 ' Set Variable initial value page=1
Page=request.querystring ("page") ' page value is an accepted value
Rs. PageSize = 20 ' show number of records per page
If not IsEmpty ("Request" ("page")) Then ' if Page has been initialized ...
page = CInt (Request ("Page")) ' receives page and assigns the page variable to a numeric type
If Page > Rs. PageCount Then ' if the number of pages received is greater than the total number of pages
Rs. AbsolutePage = Rs. PageCount ' Set the current display page equals the last page
ElseIf page <= 0 Then ' if page is less than or equal to 0
page = 1 ' Set page equals first page
Else
Rs. AbsolutePage = Page ' If greater than 0, display the current page equals the number of pages received
End If
End If
Page = Rs. Absolutepage%>
First page of paging
<%if rs.pagecount<>1 and Rs.pagecount<>0 then%> ' first to determine the total number of pages is not 1 and 0
<%if page>1 then%>
<%if Page<rs.pagecount then%>
[<a href= "<%=FILEPATH%>? page=<% = 1%> "> Home </a>]
[<a href= "<%=FILEPATH%>? page=<% = page-1%> "> Prev </a>]
[<a href= "<%=FILEPATH%>? page=<% = page + 1%> "> next </a>]
[<a href= "<%=FILEPATH%>? page=<% = Rs. Pagecount%> "> Last </a>]
<%else%>
[<a href= "<%=FILEPATH%>? page=<% = 1%> "> Home </a>]
[<a href= "<%=FILEPATH%>? page=<% = page-1%> "> Prev </a>]
[Next Page] Last
<% End If%>
<%else%>
Home [Previous Page]
[<a href= "<%=FILEPATH%>? page=<% = page + 1%> "> next </a>]
[<a href= "<%=FILEPATH%>? page=<% = Rs. Pagecount%> "> Last </a>]
<%end if%>
<%else%>
Home [Previous Page] [Next Page] Last
<%end if%>
Second page of paging
<%if rs.pagecount<>1 and Rs.pagecount<>0 then%>
<%if page>1 then%>
[<a href= "<%=FILEPATH%>? page=<% = 1%> "> Home </a>]
[<a href= "<%=FILEPATH%>? page=<% = page-1%> "> Prev </a>]
<%if Page<rs.pagecount then%>
[<a href= "<%=FILEPATH%>? page=<% = page + 1%> "> next </a>]
[<a href= "<%=FILEPATH%>? page=<% = Rs. Pagecount%> "> Last </a>]
<%else%>
[Next Page] Last
<% End If%>
<%else%>
Home [Previous Page]
[<a href= "<%=FILEPATH%>? page=<% = page + 1%> "> next </a>]
[<a href= "<%=FILEPATH%>? page=<% = Rs. Pagecount%> "> Last </a>]
<%end if%>
<%else%>
Home [Previous Page] [Next Page] Last
<%end if%>
Third Kind
<%if rs.pagecount<>1 and Rs.pagecount<>0 then%>
<%if Page<rs.pagecount then%>
<%if Page=1 then%>
Home [Previous Page]
<%else%>
[<a href= "<%=FILEPATH%>? page=<% = 1%> "> Home </a>]
[<a href= "<%=FILEPATH%>? page=<% =page-1%> "> Prev </a>]
<% End If%>
[<a href= "<%=FILEPATH%>? page=<% = page + 1%> "> next </a>]
[<a href= "<%=FILEPATH%>? page=<% = Rs. Pagecount%> "> Last </a>]
<%else%>
[<a href= "<%=FILEPATH%>? page=<% = 1%> "> Home </a>]
[<a href= "<%=FILEPATH%>? page=<% =page-1%> "> Prev </a>]
[Next Page] Last
<%end if%>
<%else%>
Home [Previous Page] [Next Page] Last
<%end if%>
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.