asp+mysql limit分页

本文介绍了一种使用ASP进行数据库分页查询的方法,包括设置每页显示的记录数、计算总页数及当前页码,并展示了如何通过链接展示前后页码以方便用户浏览。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 可以套用,测试通过
<!-- #include file="conn.asp" -->
<%
const MaxPerPage=10
records=200
pages=records/maxperpage
if pages<1 then pages=1 end if
currentpage=cint(request("currentpage"))
if currentpage="" or currentpage<1 then
  currentpage=1  
if currentpage>pages   then currentpage=pages  
end if

set rs=server.createobject("adodb.recordset")
sql="select * from view_products order by products_id desc limit "&(currentpage-1)*MaxPerPage&","&MaxPerPage
Rs.CursorLocation = 3
rs.open sql,conn
%>
<p>
<%
j=1
do while (not rs.eof) and j<=MaxPerPage
%>
  <a href="productlist.asp?products_id=<%=rs("products_id")%>"><%=((currentpage-1)*10+j)%>.<%=rs("products_name")%></a><br/>
<%
rs.movenext
j=j+1
loop
%>
第<%=currentpage%>页 共<%=Records%>条记录 共<%=Pages%>页</p>
'以下部分固定套用,显示当前页前后5页的连接
<%
ii=currentpage-5
iii=currentpage+5
if ii < 1 then
  ii=1
end if
if iii > pages then
  iii=pages
end if
if currentpage > 6 then
%><a href="index0.asp?currentpage=1">1</a> ...<%
end if
for i=ii to iii
  If i<>currentpage then
%><a href="index0.asp?currentpage=<%=i%>"><%=i%></a><%
  else
%> <%=i%><br/> <%
  end if
next
if pages > currentpage+5 then
%>... <a href="index0.asp?currentpage=<%=pages%>"><%=pages%></a><%
end if
%></p>
<%
rs.close
set rs=nothing
conn.close
set conn=nothing
%>

如果碰到查询的可以
currentpage=cint(request("currentpage"))
    if currentpage="" or currentpage<1 then        
              currentpage=1
                currentpage=cint(currentpage)
              end if
//首先对当前页面
set rs=server.CreateObject("adodb.recordset")
sql="select * from tableName where products_name like '%"&pname&"%'"
if author<>"" then
sql=sql&"and book_author_name = '"&author&"'"
end if
if isbn<>"" then
sql=sql&"and products_model='"&isbn&"'"
end if
'将所有搜索条件找齐
rs.open sql,conn,1,3      
    if rs.eof and rs.bof then str="没有商品"
        response.write(str)
    else
          records=rs.recordcount 自动计算条树
        pages=rs.pagecount     自动分页了    
              if currentpage>pages then
                    currentpage=pages
                      rs.absolutepage=currentpage
              currentpage=1
                records=0
                pages=1  
              end if
        end if
rs.close

'然后再来每个页面
if currentpage<>1 then
sql2 =sql&"order by products_id desc limit "&(currentpage-1)*10&",10"
end if
后面就跟上面一样了
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值