以下是ASP连接数据库并输出带分页的数据的代码示例:

<% ' 设置分页参数 pageSize = 10 ' 每页显示的记录数 currentPage = Request.QueryString("page") ' 当前页数 if currentPage = "" then currentPage = 1 ' 如果没有指定当前页数,则默认为第一页

' 连接数据库 set conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("data.mdb")

' 查询记录总数 set rsCount = conn.Execute("SELECT COUNT(*) AS total FROM users") total = rsCount("total") rsCount.Close

' 计算总页数 totalPages = Int((total - 1) / pageSize) + 1

' 查询当前页的记录 set rs = conn.Execute("SELECT * FROM users ORDER BY id DESC LIMIT " & (currentPage - 1) * pageSize & "," & pageSize)

' 输出记录 response.write "

" do while not rs.EOF response.write "" response.write "" response.write "" response.write "" response.write "" rs.MoveNext loop response.write "
" & rs("id") & "" & rs("name") & "" & rs("age") & "
"

' 输出分页链接 if totalPages > 1 then response.write "

" for i = 1 to totalPages if i = currentPage then response.write "" & i & "" else response.write "" & i & "" end if next response.write "
" end if

rs.Close conn.Close set rsCount = nothing set rs = nothing set conn = nothing %

asp程序中连接数据库并输出带分页的数据代码示例

原文地址: http://www.cveoy.top/t/topic/faid 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录