以下是一个简单的ASP网站分页代码示例:
<%
PerPage = 10 ‘每页显示的记录数
currentPage = Request.QueryString(“page”)
‘连接数据库并获取数据总记录数
Set Conn = Server.CreateObject(“ADODB.Connection”)
Conn.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & Server.MapPath(“mydatabase.mdb”)
Set rs = Conn.Execute(“SELECT COUNT(*) AS TotalRecords FROM mytable”)
totalRecords = rs(“TotalRecords”)
rs.Close
Conn.Close
totalPages = Ceil(totalRecords / PerPage)
If Not IsNumeric(currentPage) Or currentPage < 1 Then
currentPage = 1
End If
If currentPage > totalPages Then
currentPage = totalPages
End If
startIndex = (currentPage – 1) * PerPage
Set rs = Conn.Execute(“SELECT * FROM mytable ORDER BY ID DESC LIMIT ” & startIndex & “, ” & PerPage)
Do While Not rs.EOF
'输出数据
Response.Write rs("FieldName") & "<br>"
rs.MoveNext
Loop
If totalPages > 1 Then
For i = 1 To totalPages
If i = currentPage Then
Response.Write i & " "
Else
Response.Write "<a href='?page=" & i & "'>" & i & "</a> "
End If
Next
End If
%>
请根据您的数据库表结构和需求进行适当的更改和调整。建议在使用此代码之前先备份数据库,以防发生意外情况。
ASP网站分页代码示例:
<%
Dim PageSize, PageNum, RecordCount, TotalPages
PageSize = 10 '每页显示的记录数
PageNum = 1 '当前页码
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("数据库.mdb")
Set RS = Conn.Execute("SELECT COUNT(*) AS RecordCount FROM 表名")
RecordCount = RS.Fields("RecordCount").Value
RS.Close
Conn.Close
TotalPages = RecordCount PageSize
If RecordCount Mod PageSize <> 0 Then
TotalPages = TotalPages + 1
End If
If Request.QueryString("Page") <> "" Then
PageNum = Request.QueryString("Page")
If PageNum < 1 Then
PageNum = 1
ElseIf PageNum > TotalPages Then
PageNum = TotalPages
End If
End If
Set RS = Conn.Execute("SELECT * FROM 表名 ORDER BY ID DESC")
RS.PageSize = PageSize
RS.AbsolutePage = PageNum
%>
<h1>分页数据列表</h1>
<table border="1" cellspacing="0" cellpadding="5">
<%
Do While Not RS.EOF
%>
<tr>
<td><%=RS("ID")%></td>
<td><%=RS("名称")%></td>
</tr>
<%
RS.MoveNext
Loop
%>
</table>
<% If TotalPages > 1 Then %>
<div>
<%
For i = 1 To TotalPages
If i = PageNum Then
%>
<span><%=i%></span>
<%
Else
%>
<a href="?Page=<%=i%>"><%=i%></a>
<%
End If
Next
%>
</div>
<% End If %>
<%
RS.Close
Conn.Close
Set RS = Nothing
Set Conn = Nothing
%>
发布者:luotuoemo,转转请注明出处:https://www.jintuiyun.com/156783.html