ASP + Access2000 Efficient Paging program

Source: Internet
Author: User


<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<%

On Error Resume Next
Dim startime,endtime
Startime=timer ()

' Connect to the database
Dim db,conn,rs
db = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("./db.mdb")
Set conn = Server.CreateObject ("Adodb.connection")
Set rs = Server.CreateObject ("Adodb.recordset")
Conn.Open DB
%>

<%
'**************
' Pager bar function
' Output wzpage value
'**************
Function Pagination (PageCount)
Dim Wzpage,wzpagecount,pagenum,boardid
Boardid = Request.QueryString ("board_id")
If boardid = 0 Then boardid = 1
If Len (Request.QueryString ("page")) <>0 Then
Wzpage = CLng (request.querystring ("page"))
Else
Wzpage =1
End If
If wzpage <= 0 Then wzpage =1
Pagenum = (wzpage 10) *10+1
If wzpage mod = 0 Then pagenum = (wzpage 10) *10-9
If wzpage > Then
Response.Write ("<font face=" "Webdings" ">")
Response.Write ("<a href=" "Board_id=" & Boardid & "&page=1" "title=" "Home" ">9</a>")
Response.Write ("<a href=" "Board_id=" & Boardid & "&page=" & Pagenum-1 & "" title= "" Top 10 pages "" >7 </a> ")
Response.Write ("</font>")
End If
For pagenum = Pagenum to Pagenum + 9
If pagenum = Wzpage Then
Response.Write ("<font color=" "#ff0000" ">")
Response.Write ("[" & Pagenum & "]")
Response.Write ("</font>")
Else
Response.Write ("<a href=" "Board_id=" & Boardid & "&page=" & Pagenum & "" ">")
Response.Write ("[" & Pagenum & "]")
Response.Write ("</a>")
End If
If pagenum >= PageCount Then Exit for
Next
If Wzpage < (PageCount-(PageCount)) Then
Response.Write ("<font face=" "Webdings" ">")
Response.Write ("<a href=" "Board_id=" & Boardid & "&page=" & Pagenum & "" title= "" after 10 pages "" >8< /a> ")
Response.Write ("<a href=" "Board_id=" & Boardid & "&page=" & PageCount & "" "Title=" "Last" "": </a> ")
Response.Write ("</font>")
End If
End Function
%>

<%
Dim rssql,getstring
GetString = CLng (Request.QueryString ("board_id"))
If GetString = 0 Then GetString = 1

'******************************************
' Take the total number of articles and repeat the number of pages per page, prepare pagination
' Wzcount The total number of articles
' Wzrep the number of repeated display bars
' Wzpage paging parameter ID
' Wzpagecount Total pages
'******************************************
Dim wzcount,wzrep,wzpage,wzpagecount,wzpagerep,boardstr
Wzrep = 30
' Rssql = ' select count (id) from ' table1 '
' Rs.Open rssql,conn,0,1,&h0001
Wzcount = Conn.execute ("SELECT count (id) from ' table1 '", 0, 1) (0)
' Rs.close
Wzpagecount = ABS (int (-abs (wzcount/wzrep)))
Wzpage = CLng (request.querystring ("page"))
If Len (wzpage) = 0 or wzpage = 0 Then wzpage = 1
%>
<title> pagination Test </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<link rel= "stylesheet" href= "Page.css" type= "Text/css" >
<body>
<table width= "760" border= "1" cellspacing= "0" cellpadding= "4" align= "center" bordercolordark= "#ffffff" bordercolorlight= "#cccccc" >
&LT;TR align= "center" >
&LT;TD width= ">ID</td>"
&LT;TD width= > Title </td>
&LT;TD width= "*" > Content (Display first 20 words) </td>
&LT;TD width= > Time </td>
</tr>
<%
' Take a list of articles
Rssql = "Select ID,AAAA,BBBB,CCCC from ' table1 '"
Rs.Open rssql,conn,1,1,&h0001
' Get current page record according to paging parameter
rs.absoluteposition=rs.absoluteposition+ (ABS (Wzpage)-1) *wzrep)
' Show article title list
If rs.eof or Rs.bof then%>
<tr>
<td > No record </td>
</tr>
<% Else
Dim I,bgcolor
For i = 0 to Wzrep-1
If Rs.eof then exit for
' While not rs.eof and I <= wzrep
Bgcolor= "#FFFFFF"
If I mod 2=0 then bgcolor= "#DFEFFF"
%>
<tr bgcolor= "<%=bgColor%>" >
&LT;TD width= "><%=rs" (0)%></td>
&LT;TD width= "><%=rs" (1)%></td>
&LT;TD width= "*" ><%=left (RS (2),)%></td>
&LT;TD width= "><%=rs" (3)%></td>
</tr>
<%
Rs.movenext
' I=i+1
' Wend
Next
End If
%>
</table>
<table width= "760" border= "0" cellspacing= "2" cellpadding= "2" align= "Center" >
<tr>
&LT;TD align= "left" width= "> A total <font color=red><%= wzcount%></font> strip <font <%= wzrep%></font>/page <font color=red><%= wzpagecount%></font> page </td>
&LT;TD align= "Right" > <%= pagination (wzpagecount)%></td>
</tr>
</table>

<table width= "760" border= "0" align= "center" cellpadding= "2" cellspacing= "2" >
<tr>
&LT;TD align= "center" >
<%endtime=timer ()%>
This page execution time: <%=formatnumber ((endtime-startime) *1000,3)%> Ms </td>
</tr>
</table>
</body>
<%
' Releasing resources
Rs.close
Set rs = Nothing
Conn.close
Set conn = Nothing
%>

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.