“无限流”分页程序的难题!!!

wsq0931 2006-04-24 08:18:55
代码如下,点击上页和下页没有反应,不知道哪里出问题了!
请高手指教!!!

<%
'Option Explicit
'Response.Flush
Dim BeginTime,EndTime
BeginTime=Timer
Dim conn,SQLstr,Rs,DefRecordNum,CursorBegin,CursorEnd,CurPageNum,hav
DefRecordNum=50

'--------------获取相关参数----------
If Request("CursorBegin")="" Then CursorBegin=0 Else CursorBegin=Request("CursorBegin")
If Request("CursorEnd")="" Then CursorEnd=0 Else CursorEnd=Request("CursorEnd")
If Request("CurPageNum")<>"" Then
CurPageNum=CLng(Request("CurPageNum"))
If CurPageNum<=0 Then CurPageNum=1
Else
CurPageNum=1
End If
hav=Request("hav")
If hav="" Then hav="next"
'----------------End-----------------

'------------显示翻页内容函数--------
Function TurnPageFS(DispRecordNum)
Dim n
While Not(Rs.Eof) And n<DispRecordNum
n=n+1
Response.Write "<tr>"&_
"<td bgcolor='efefef'>"&Rs(0)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(1)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(2)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(3)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(4)&"</td>"&_
"<td bgcolor='efefef'>"&Rs(5)&"</td>"&_
"</tr>"
If n=1 Then CursorBegin=Rs(0)
If n=DefRecordNum Or Rs.Eof Then CursorEnd=Rs(0)
Rs.MoveNext
Wend
End Function

'-------------连接数据库-------------
Set conn=Server.CreateObject("Adodb.Connection")
'SQLstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.Mappath("mldata.mdb")
SQLstr="Driver={SQL Server};server=127.0.0.1;uid=sa;pwd=123456789;database=wsqdata"
conn.Open SQLstr

'---------统计总记录数/总页数---------
'-PS:推荐使用count(ID),ID为自动编号且索引,否则速度有可能大打折扣
'-PS:此统计是本程序中最耗资源的一部分,如果取消这段程序,速度会快上10倍左右
Dim TotalRecords,TotalPages
SQLstr="Select count(ID) As RecordSum From soft"
Set Rs=conn.Execute(SQLstr,0,1)
TotalRecords=Rs("RecordSum")
TotalPages=Abs(Int(TotalRecords/DefRecordNum*(-1)))
Rs.Close
Set Rs=Nothing

'--------根据hav选择相应的SQL字串-----
Select Case(hav)
Case "back"
CursorEnd=CursorBegin
SQLstr="Select Top "&DefRecordNum&" softid,zlname,wjsize,fbtime,id,gllx From soft Where softid<"&CursorBegin&_
" And softid In (Select Top "&DefRecordNum&" softid From soft Where softid<"&CursorBegin&" Order by softid DESC) Order by softid"
Case "next"
SQLstr="Select Top "&DefRecordNum&" softid,zlname,wjsize,fbtime,id,gllx From soft Where softid>"&CursorEnd&_
" Order by softid"
End Select
Set Rs=conn.Execute(SQLstr,0,1)
%>
<html>
<head>
<title>"无限流"分页程序  作者:Arbiter</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">td,br,div,p,body {font-size:12px}</style>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
<table width="100%" border="1" cellspacing="0" cellpadding="3" bgcolor="#CCCCCC">
<tr>
<td>ID</td>
<td>Title</td>
<td>FileName</td>
<td>大小</td>
<td>尺寸</td>
<td>类别</td>
</tr>
<%
TurnPageFS(DefRecordNum)
Rs.Close
Set Rs=Nothing
conn.Close
Set conn=Nothing
%>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="3" bgcolor="#E2F5FE">
<tr align="center">
<td colspan="2"><%Response.Write CurPageNum&"/"&TotalPages&"页 总记录数:"&TotalRecords%></td>
<td><a href="fenye.asp">首页</a> <a href=javascript:turnpage('back');>上一页</a>
<a href=javascript:turnpage('next');>下一页</a> </td>
</tr>
</table>
<%
EndTime=Timer
Response.Write "<br>程序执行时间:"&(EndTime-BeginTime)*1000&"毫秒"
Response.Write " 第一条记录的ID值(CursorBegin)="&CursorBegin&" "
Response.Write "最后一条记录的ID值(CursorEnd)="&CursorEnd&"<br><br>"
%>
<script language="javascript">
function turnpage(func){
var CurPageNum=<%=CurPageNum%>; //取得当前页码
var CursorBegin=<%=CursorBegin%>; //取得第一个显示的记录的ID值
var CursorEnd=<%=CursorEnd%>; //取得最后一个显示的记录的ID值
var TotalPages=<%=TotalPages%>; //取得页面总数

var BackUrl='fenye.asp?CurPageNum='+(CurPageNum-1)+'&CursorBegin='+CursorBegin+'&CursorEnd='+CursorEnd+'&hav=back';
var NextUrl='fenye.asp?CurPageNum='+(CurPageNum+1)+'&CursorBegin='+CursorBegin+'&CursorEnd='+CursorEnd+'&hav=next';
if(CurPageNum<=1 && func=='back'){
location.href='#';
}else if(CurPageNum>=TotalPages && func=='next'){
location.href='#';
}else if(func=='back'){
location.href=BackUrl;
}else if(func=='next'){
location.href=NextUrl;
}
}
</script>
</body>
</html>
...全文
177 5 打赏 收藏 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangjingcheng 2006-05-16
  • 打赏
  • 举报
回复
简单的分页程序
先创建一个rscL记录集
'===========================
set rsCL=server.CreateObject("adodb.recordset")
mysql = "select * from tbl_customer order by id desc"
rsCL.open mysql,conn,1,1
'=================================================
利用
while not rscl.eof
response.write rscl.fields("f1")
rscl.movenext
wend
输出所有记录。
利用下面代码替换while not rscl.eof
'===============================================
i = 1
PageNo=replace(request("PageNo"),"'","")
if not Isnumeric(PageNo) then
PageNo=1
end if
rsCL.pagesize=30 '每页多少纪录
TotalPages=rsCL.pagecount
if PageNo="" or PageNo<1 then
PageNo=1
end if
if len(PageNo)>=5 then PageNo=1
if cint(pageNo)>cint(totalpages) then
pageNo=rsCL.pagecount
end if
totalpage=rsCL.pagecount
totalrecord=rsCL.recordcount
rsCL.AbsolutePage = PageNo
RowCount=rsCL.pagesize
while not rsCL.eof and Rowcount>0
'===================================================


利用下面代码替换wend
'===================================================
i = i + 1
rowcount=rowcount-1
rsCL.movenext
wend
'===================================================

下面是现实上一页下一页的代码,一般放在表格下面就行了

<form name="frmPage" action="" method="get">
<table width="95%" align="center" class="no12">
<tr>
<td width="54%" align="left" class="black">
<%
if pageNo="" then pageno=1
if totalPages="" then TotalPages=1
if PageNo > 1 Then
response.write "<a href=?PageNo=1>首页</a> | <a href=?PageNo=" & (PageNo-1) & ">上一页</a> | "
end if
if TotalPages > 1 and cint(PageNo) <> cint(TotalPages) then
response.write "<a href=?PageNo=" & (PageNo+1) & ">下一页</a> | <a href=?PageNo=" & TotalPages & ">末页</a> "
end if
%>
</td>
<td width="22%" align="left" class="black"><%=TotalRecord%></td>
<td width="24%" align="left">
<%Response.Write "Page:"& PageNo &" / "& TotalPages%>
<input name="pageNo" type="text" id="pageNo" size="2" maxlength="5">
<input name="button2" type="submit" class="smb_btn" id="button2" value="GoTo">
</td>
</tr>
</table>
</form>
zhangjingcheng 2006-05-16
  • 打赏
  • 举报
回复
用一下我的分页的代码
kaijier 2006-05-16
  • 打赏
  • 举报
回复
学习一下
evaf_01 2006-05-16
  • 打赏
  • 举报
回复
有谁调试成功呵???加分!!!
wsq0931 2006-04-24
  • 打赏
  • 举报
回复
而且总记录数也是错的,老是显示10

28,402

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧