ASP access the method of paging the large amount of data

Source: Internet
Author: User

' This sub-page effect support ' pagination, pagination effect: Home prev ... 2 3 4 5 6 7 ... Next last page This paging mode, has the forum style
' ID title content status updatetime
' 1 T1 C1 1 2010-5-26 21:16:06
' 2 T2 C2 1 2010-5-26 21:16:09
' 3 t3 c3 1 2010-5-26 21:16:12
' 4 T4 c4 1 2010-5-26 21:16:15
' 5 T5 c5 1 2010-5-26 21:16:23


db= "Database/db1.mdb"
Path=server.mappath (DB)
Set Conn=server.createobject ("ADODB. Connection ")
Connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" &path
Conn. Open ConnStr
Set Rs=server. CreateObject ("Adodb.recordset")


%>

<!--#include file= "conn.asp"-->
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<meta name= "generator" content= "EditPlus" >
<meta name= "Author" content= "" >
<meta name= "Keywords" content= "" >
<meta name= "Description" content= "" >
<style>
td{
font-size:12px;
}
</style>
</HEAD>

<BODY>

<table border=1 cellspacing=0 cellpadding=0 width=500>
<TR>
&LT;TD align= "center" >ID</td>
&LT;TD height= "align=" "Center" > title </TD>
&LT;TD align= "center" > Time </TD>
</TR>
<%
' Pagination method for more than 100,000 data
' Author: wangsdong
' Source: 111cn.net
' Original document, reprint please keep this information, thank you
Keyword=request ("keyword")
Page=request ("page")
If page= "" "Or Not IsNumeric (page) then page=1 Else page=cint (page)
page_size=2
Q1= "and Status>0"
If keyword<> "Please enter the keyword" and keyword<> "" Then
q1=q1& "and title like '%" &keyword& "%"
End If
If Page>1 Then
Sql= ' select top ' &page_size& ' id,title,content,updatetime from news where 1=1 and id< (select min (IDs) from (Sele CT Top ' & (page-1) *page_size& ' ID from news where status>0 ' &q1& ' ORDER by id DESC ' as C1) '
Else
Sql= ' select top ' &page_size& ' id,title,content,updatetime from news where 1=1 '
End If
sql=sql&q1& "ORDER BY id DESC"
Set Rs=server. CreateObject ("Adodb.recordset")
Rs.Open sql,conn,1,1
If not rs.eof then
Do as not rs.eof
ID=RS ("id")
Title=rs ("title")
Content=rs ("content")
Updatetime=rs ("UpdateTime")
' The contents of the ************* cycle begin ************************
%>
<TR>
<td><%=id%></td>
&LT;TD height= "><%=title%></TD>"
<TD><%=updatetime%></TD>
</TR>
<%
' ************* the contents of the Loop End ************************
Rs.movenext
Loop
End If
Rs.close
%>
&LT;TR&GT;&LT;TD colspan= "3" height= "a" align= "center" >
<%
' Paging start
' Calculate total Pages
Page_count=1
Sql= "SELECT COUNT (*) as T" from News where 1=1 "&q1
Rs.Open sql,conn,1,1
If Rs.eof Then
Else
Recordset_count=rs ("T")
If Recordset_count mod page_size=0 then
Page_count=recordset_countpage_size
Else
Page_count=recordset_countpage_size+1
End If
End If
Rs.close
' Pagination, pagination effect: First prev ... 2 3 4 5 6 7 ... Next Page last page
If Page=1 Then
Response.Write "Home &nbsp; prev &nbsp;"
Else
Response.Write "<a href=" "page=1&keyword=" &keyword& "" > Home </a>&nbsp;<a href= ""? Page= "&page-1&" &keyword= "&keyword&" "> previous page </a>&nbsp;"
End If
If Page>4 Then
S=page-3
Response.Write "..."
Else
S=1
End If
If Page<=page_count-3 Then
E=page+3
Else
E=page_count
End If
For I=s to E
If I=page Then
Response.Write "<font color=" "#FF8000" "><b>" &i& "</b></font>&nbsp;"
Else
Response.Write "<a href=" "page=" &i& "&keyword=" &keyword& "" > "&i&" </a> &nbsp; "
End If
Next

If Page<page_count-3 Then
Response.Write "..."
End If
If Page=cint (Page_count) Then
Response.Write "<span> next page &nbsp; last page </span>"
Else
Response.Write "<span><a href=" "page=" &page+1& "&keyword=" &keyword& "" "> Next page </a >&nbsp;<a href= ""? page= "&page_count&" &keyword= &keyword& "" "> Last page </a>< /SPAN> "
End If

%>

</td></tr>


</TABLE>
</BODY>
</HTML>

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.