快疯了!严重求救!!!调了一夜都没调出来,菜鸟在asp分页上栽大跟头了!谢谢!在线等!

deng4437 2010-01-16 07:47:23
我最近在写一个留言板,快写好了

昨天夜里在调分页,我用是access2003的数据库,最后郁闷死了
其实,数据都对的,比如我每页设pagesize为2,我数据库里一共7个记录,最后我测试系统它报出来的pagecount,absolutepage等等各项数据都是对,我都一步一步调的,可是问题就在于为什么只能显示第1页,从显示第2页,第3页的时候页面就全部是空的,一个数据也没有,但是下面目录的页码全部是对的,比如说到第4页了就停了(最后一页了),后来我调了半天发现从二页开始recordset的eof,就为真了!
我狂晕!我一共7个记录,它第一页只显示了2个(每页2个),怎么可能在第二页的时候,rs.eof就真了?!!!




<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>自制留言板</title>
<script type="text/JavaScript">
<!--

//-->
</script>
<style type="text/css">
<!--
input
{
border:thin
}

body,input{background-color:#FFFFFF;}

textarea
{

background:#FFFFFF;
}

.display { visibility:visibile ;z-index:3;
width:500px;
height:300px;
position:absolute;
z-index:1;
border-width:thick;
text-align:center;}

body{
text-align:center;
}
.undisplay { visibility:hidden ;z-index:1;width:500px;
height:300px;
position:absolute;
z-index:1;
border-width:thick;
text-align:center;}
span
{

color:#FF0066
}
textarea
{

z-index:2;


}

table td span
{
height:60px;
width;60px;
text-align:left;

}




-->

</style>
</head>


<body>
<table><tr><td><table height= "500" width="1000" border="1" cellspacing="0" cellpadding="0">
<caption style=" font-size:24px;"align="top">
留言板
</caption>
<%
dim cnn,cnnstr,sqlsave,sqlread,rs,nickname,comments,page,temp,num

nickname=Request("nickname")
comments=Request("comments")
page=request.querystring("page")

set cnn=Server.CreateObject("ADODB.Connection")
set rs=Server.CreateObject("ADODB.Recordset")
cnnstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("mdb\comments.mdb")
sqlsave="INSERT INTO MAIN VALUES ("&"'"&nickname &"'"&","&"'"&comments&"')"
sqlread="SELECT * FROM MAIN"
cnn.open cnnstr







if nickname<>"" and comments<>"" then

'response.write("<script>alert("""&nickname&""");</script>")
rs.open sqlsave,cnn,1,3

End if

rs.open sqlread,cnn,3,2

if page<1 or page=null or page="" then
page=1

else
page=clng(page)
end if

if not (rs.eof and rs.bof) then

rs.absolutepage=page

rs.pagesize=2


num=1

do while not(rs.eof or num>rs.pagesize)

temp=replace(rs("comments"),vbcrlf,"<br>")
temp = Replace(temp,"em<","<img src=""pic\兔斯基QQ表情")
temp = replace(temp,"em>",".gif""></img>")



response.write "<tr align=""left""><td width=""150"">"&"游客:"&rs("nickname")&"</td><td align=""left"">"&temp&"</td></tr>"
num=num+1
rs.MoveNext


loop

end if

%>
</table></td></tr>

<tr>
<td coslpan="2">
<%
response.write("<script>alert("""&rs.recordcount&""");</script>")
if page<>1 and page <> rs.pagecount then

response.write("<a href=""index.asp?page=1"">第一页</a> ")
response.write("<a href=""index.asp?page="&page-1&""">"&"上一页"&"</a> ")
response.write(page&" ")
response.write("<a href=""index.asp?page="&page+1&""">"&"下一页"&"</a> ")
response.write("<a href=""index.asp?page="&rs.pagecount&""">"&"最后一页"&"</a> ")

elseif page=1 then
response.write("<a href=""index.asp?page="&page+1&""">"&"下一页"&"</a> ")
response.write("<a href=""index.asp?page="&rs.pagecount&""">"&"最后一页"&"</a> ")

elseif page=rs.pagecount then
response.write("<a href=""index.asp?page=1"">1</a> ")
response.write("<a href=""index.asp?page="&page-1&""">"&"上一页"&"</a> ")
response.write(page&" ")
end if

rs.close
set rs=nothing
set cnn=nothing
%>
</td>

</tr>



<tr>
<td>
<div align="left" >
<form action="index.asp" method="post" onsubmit="return check();">昵称:
<input name="nickname" type="text" size="7" height="23" />
<span ><a onclick="document.getElementById('expression').className='display';" href="#">插入表情</a></span>
<table id="expression" class="undisplay" >
<tr>
<th align="center" cellspacing="10" colspan="6">
<a style="color:#FF0000;" id="closebutton"href="#">关闭</a> </th >
</tr>
<%
dim i,j,cols,rows
cols=5
rows=5

for i=0 to rows
response.Write("<tr>")
for j=0 to cols
response.write("<td bordercolor=""red"" ><a href=#><img value="&"em<"&(j+i*(rows+1))+1&"em>"&" src=pic\兔斯基QQ表情"&(j+i*(rows+1))+1&".gif></img></a></td>")

next
response.write("</tr>")
next

%>
</table>
<textarea style=" display:block;"rows = "20" cols = "88" name="comments" wrap="physical"></textarea>
<input name="submit" value="submit" type="submit" />
<input name="reset" value="reset" type="reset" />
</form>
</div>
</td></tr></table>


</body>
<script type="text/javascript">

var i = document.getElementsByTagName("img").length;
var temp=document.getElementsByTagName("img");
for(var j = 0 ; j< i;j++)
{
temp[j].onclick=function()
{
document.getElementsByTagName("textarea")[0].value+=this.value;


}

}

document.getElementById("closebutton").onclick=function (){
document.getElementById("expression").className="undisplay";

}

function check()
{

var tt = document.getElementsByTagName("input")[0];
var comments = document.getElementsByTagName("textarea")[0];

if(tt.value && comments.value)
{ alert("留言已经成功提交!");
return true;
}
alert("不能留空!");
return false;



}

</script>
</html>



...全文
67 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
deng4437 2010-01-16
  • 打赏
  • 举报
回复
问题原因,我已经找到了,而且改了后完全成功了!
不过还是要谢谢楼上的!特别是看了你的头像,有种说不出的感觉
(曾经看了那片子郁闷好长一段时间,后来好不容易从那阴影里走了出来..)
握握手,同仁..你的人生观一定够棒,

好,言归正传...
问题的原因出在了
rs.pagesize
和rs.absolutepage上面,上面这个程序只要把

rs.absolutepage=page
rs.pagesize=2


上面两行代码,倒一倒,就正常好了,也就是一定要先设置pagesize然后再设置absolutpage,不然就出问题了,我测试过了,如果设置倒了的话,等显示到第二页的时候,rs.absolutepositionr值居然到了-3 !!!
按照正常逻辑,我设置了一页显示5个记录,第二页absoluteposition应该是6,7,8,9,10才对,难怪程序要eof返回真了!


不知有谁能否讲解这一下这其中的详细原因,谢谢!
街头小贩 2010-01-16
  • 打赏
  • 举报
回复
index.asp?page=?
当page的值>1时!以下值从哪获取呀
nickname=Request("nickname")
comments=Request("comments")
你要是要用,哪才不正常呢?一般有两种表单和URL字符串!给你看一个URL字符串吧!

<%
Function makeWordsArray(strWords)
Dim wordsarray
If InStr(strRecords,",")>0 then
wordsarray=Split(strRecords,",")
ElseIf InStr(strRecords," ")>0 then
wordsarray=Split(strRecords," ")
Else
wordsarray=array(strRecords)
End If
makeWordsArray=wordsarray
End Function


Dim strCatagory,strRecords,strBrand
Dim strSymbol:strSymbol=5 '大于ratemodel数组的上限即可
Dim strSQL,strKeyarray
Dim strMessage,strSitePrix

strCatagory=Trim(Request("catagory"))
strRecords=Trim(Request("record"))
strBrand=LCase(Trim(Request("brand")))


If Not IsEmpty(Request("catagory")) Or strCatagory<>"" then
If seekArray(ratemodel,strCatagory) then
strSymbol=getArrayIndex(ratemodel,strCatagory)
End If
Else
strBrand=false
End If

If strRecords<>"" then
strKeyarray=makeWordsArray(strRecords)
'Response.write "------------------------------------------->"&UBound(strKeyarray)
else
strKeyarray=""
'Response.write "------------------------------------------->"&strKeyarray
end if%>
<html>
....
<%

Dim jumpPage:jumpPage="relates.asp?brand="&strBrand&"&catagory="&strCatagory&"&record="&strRecords
'...
%>
<div id="pagepanel"> <%call showpage(jumpPage,strRs.RecordCount,strRs.PageSize,CurrentPage,5,"current",true)%> </div>

注意:jumpPage的变化.showpage过程如下:

<%

'***********************************************
'函数名:PasteURL
'作 用:向地址中加入 ? 或 &
'参 数:strUrl ----网址
'返回值:加了 ? 或 & 的网址
'***********************************************
function PasteURL(strUrl)
if strUrl="" then
PasteURL=""
exit function
end if
'如果传入的URL末尾不是"?",有两种情况:
'1.无“?”,此时需加入一个“?”
'2. 有“?”再判断有无“&”
if InStr(strUrl,"?")<len(strUrl) then
if InStr(strUrl,"?")>1 then
if InStr(strUrl,"&")<len(strUrl) then
PasteURL=strUrl & "&"
else
PasteURL=strUrl
end if
else
PasteURL=strUrl & "?"
end if
else
PasteURL=strUrl
end if
end function

'***********************************************
'过程名:ShowPage
'作 用:显示“上一页 下一页”等信息
'参 数:sDesURL ----链接地址,可以是一个文件名,也可以是一个有一些参数所URL
' nTotalNumber ----总数量
' nMaxPerPage ----每页数量
' nCurrentPage ----当前页
' nBlock ----数字页码可示段的数量
' cPageStyle ----当前页码的CSS样式
' bSymbol ----是否显示标记位
'***********************************************
sub ShowPage(sDesURL, nTotalNumber, nMaxPerPage, nCurrentPage,nBlock,cPageStyle,bSymbol)
dim n, i,strTemp,strUrl,strStyle,poutStr
'计算页数
if nTotalNumber mod nMaxPerPage=0 then
n= nTotalNumber \ nMaxPerPage
else
n= nTotalNumber \ nMaxPerPage+1
end if
'判断nCurrentPage
if nCurrentPage < 1 then
nCurrentPage = 1
elseif nCurrentPage > n then
nCurrentPage = n
end if
strStyle=cPageStyle
If strStyle="" then strStyle="current"
'根据输入的sDesURL向它加入?或&
strUrl=PasteURL(sDesURL)
poutStr="<dl>"
if nCurrentPage<2 then
poutStr=poutStr&"<dt>INDEX</dt> <dt>PREV</dt>"
else
poutStr=poutStr& "<dt><a href='" & strUrl & "page=1'>INDEX</a></dt>"
poutStr=poutStr& "<dt><a href='" & strUrl & "page=" & (nCurrentPage-1) & "'>PREV</a></dt>"
end if
'mm页码标量
'limax数字页码的可示上限
'lilow数字页码的可示下限
'lisymbol上一个可示段的上限
'outStr数字页码的缓存字符串
Dim mm,limax,lilow,lisymbol,outStr

If n>1 then
outStr= "<dd><ul>"
'数字页码的可示上限
if nCurrentPage Mod nBlock >0 then
limax=((nCurrentPage \ nBlock) * nBlock) + nBlock
else
limax=(nCurrentPage \ nBlock) * nBlock
end if
'数字页码的可示下限
lilow=limax - nBlock+1
if limax>n then limax=n
'显示上一个标记位
if bSymbol then
if lilow mod nBlock>0 And lilow>1 then
lisymbol=lilow - 1 - nBlock
if lisymbol=0 then lisymbol=1
outStr=outStr& "<li><a href='" & strUrl & "page="&lisymbol&"'>"&lisymbol&"</a></li><li> ... </li>"
end if
end if
'打印数字页码
for mm=lilow to limax
outStr=outStr& "<li>"
if mm=nCurrentPage then
outStr=outStr& "<span class='"&strStyle&"'>"&mm&"</span>"
else
outStr=outStr& "<a href='" & strUrl & "page="&mm&"'>"&mm&"</a>"
end if
outStr=outStr& "</li>"
next
'显示最后一个标记位
if bSymbol then
if limax<n then
outStr=outStr& "<li> ... </li><li><a href='" & strUrl & "page="&n&"'>"&n&"</a></li>"
end if
end if
outStr=outStr& "</ul></dd>"
poutStr=poutStr&""&outStr
End If
if n-nCurrentPage<1 then
poutStr=poutStr& "<dt>NEXT</dt><dt>END</dt>"
else
poutStr=poutStr& "<dt><a href='" & strUrl & "page=" & (nCurrentPage+1) & "'>NEXT</a></dt>"
poutStr=poutStr& "<dt><a href='" & strUrl & "page=" & n & "'>END</a></dt>"
end if
poutStr=poutStr&"</dl><label>showing "&((nCurrentPage-1)*nMaxPerPage)+1&" - "
if nCurrentPage*nMaxPerPage> nTotalNumber then
poutStr=poutStr&""&nTotalNumber
else
poutStr=poutStr&""&nCurrentPage*nMaxPerPage
end if
poutStr=poutStr&" of "&nTotalNumber&"</label>"
Response.Write poutStr
end sub
%>

28,390

社区成员

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

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