ASP查询分页问题

rollin5460 2008-12-03 11:58:35
我想做一个查询分页,现在好像有问题。现在的代码实现了一进页面就可以分页显示所有的记录。但是如果我输入查询条件之后,能够得到分页显示,但是只有第一页是符合条件了,后面的页的记录都是之前的那些记录。请大家帮帮忙。还有,我想把我的功能改成一进页面显示部分为空,不用显示所有的记录,当输入查询条件之后再分页显示,我现在的代码如下,请大家帮忙看看,谢谢啦!



[code=ASP][/code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- #include file="conn.asp" -->
<!--#include file="Function.asp"-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>DCC Database System</title>

</head>
<%
docid=request("id")
if docid<>"" then
conn.execute "delete from doclist where ID="& docid
end if
%>

<%
getdocno=Trim(Request("getdocno"))
getrev=Trim(Request("getrev"))
getproject=Trim(Request("getproject"))
page=clng(request("page"))
if page<1 then page=1
if page>rs.recordcount then page=rs.recordcount
Set rs=CreateObject("ADODB.RecordSet")
sql="Select * from doclist where Doc_no like '%"& getdocno &"%' and Project like '%"& getproject &"%' "
rs.Open sql,conn,1,1
rs.movefirst
If Not rs.EOF Then
rs.Pagesize=20
rs.Absolutepage=Page
End If
%>
<body>
<form id="myform" name="myform" method="post" action="">
<table width="970" border="0" cellspacing="0" cellpadding="0" align="center" height="269" >
<tr>
<td height="260" valign="bottom" bordercolor="#9966CC" background="images/top.jpg">
<table width="700" border="0" align="right" cellpadding="0" cellspacing="0" height="19">
<tr>
<td width="109" height="19" align="center" valign="middle"><b><a href="newdoc.asp">
New DOC</a></b></td>
<td width="101" height="19" align="center" valign="middle"><b>
<a href="editdoc.asp">Edit DOC</a></b></td>
<td width="123" height="19" align="center" valign="middle">search</td>
<td width="104" height="19" align="center" valign="middle">history</td>
<td width="146" height="19" align="center" valign="middle">chang
password</td>
<td width="107" height="19"> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="9" align="center" valign="top" background="images/line.jpg">

<table border="0" width="96%" id="table1" height="176">
<tr>
<td height="67">
<table border="0" width="100%" id="table2" height="75">
<tr>
<td height="37" align="left">
<img border="0" src="images/ico02.gif" width="32" height="32"> <font size="4" color="#9999FF">
<b>Edit Document</b></td>
</tr>
<tr>
<td bgcolor="#E7F0FA" align="left" >    <b>
<font color="#FF0000">Doc_no:</font></b><font size="3"><input type="text" name="getdocno" value="<%=request("getdocno")%>" size="27" ></font><b>    
<font color="#FF0000">Project:</font></b><font size="3">
<select size="1" name="getproject">

<option>N/A</option>
<%
Dim rsPro,ProName,selProName
Set rsPro=Server.CreateObject("ADODB.RecordSet")
selProName=Request("getproject")
rsPro.Open "select * from project_info order by project asc",conn,1,1
ProName=""
rsPro.movefirst
IF rsPro.EOF Then
Response.Write "<option>No record in the database!</option>"
Else
Do while not rsPro.EOF
IF trim(rsPro("project"))<>ProName Then
IF selProName=trim(rsPro("project")) Then
Response.Write "<option selected "
Response.Write "value='"&rsPro("project")&"' >"
Response.Write rsPro("project")&"</option>"




Else
Response.Write "<option value='"&rsPro("project")&"' >"
Response.Write rsPro("project")&"</option>"




End IF
ProName=rsPro("project")
End IF

rsPro.MoveNext
Loop
End IF
'关闭用过的ADODB.RecordSet
rsPro.Close
Set rsPro=Nothing

%>

</select></font><b>    
</b><font size="3">
<input type="submit" value="Search" name="search"></font></td>
</tr>
</table>
<table border="0" width="100%" id="table3">
<tr>
<td align="right">
<%PageBreak Page,"editdoc.asp?docno="&getdocno&"&rev="&getrev&"&project="&getproject&"&",rs%>
  </td>
</tr>
</table>
</td>
</tr>


<tr>
<td>

<table border="0" width="100%" id="table4" height="66" style="border-style: solid; border-width: 2px" bordercolor="#000000">

<tr bgcolor="#9AA7ED" >
<td width="132" height="18%" align="center"><b>
<font color="#FFFFFF" size="2">Doc No</font></b></td>
<td width="24" height="18%"><b>
<font color="#FFFFFF" size="2">Rev</font></b></td>
<td width="56" height="18%" align="center"><b>
<font color="#FFFFFF" size="2">Project</font></b></td>
<td width="74" height="18%" align="center"><b>
<font color="#FFFFFF" size="2">Model</font></b></td>
<td width="175" height="18%" align="center"><b>
<font color="#FFFFFF" size="2">Description</font></b></td>
<td width="115" height="18%" align="center"><b>
<font color="#FFFFFF" size="2">Effective Date</font></b></td>
<td width="113" height="18%" align="center"><b>
<font color="#FFFFFF" size="2">Obsolete Date</font></b></td>
<td width="24" height="18%" align="center"><b>
<font color="#FFFFFF" size="2">DMR</font></b></td>
<td width="62" height="18%" align="center"><b>
<font color="#FFFFFF" size="2">Modify</font></b></td>
<td width="59" height="18%" align="center"><b>
<font color="#FFFFFF" size="2">Save as</font></b></td>
<td height="18%" align="center"><b>
<font color="#FFFFFF" size="2">
Delete</font></b></td>
</tr>
<% for i=1 to rs.pagesize
%>

<tr bgcolor="#ececec" align="center" onMouseOver="this.bgColor='#B0E2FF'" onMouseOut="this.bgColor='#ececec'">
<td width="132"><font size="2"><%=rs("Doc_no")%> </font></td>
<td width="24"><font size="2"><%=rs("Rev")%> </font></td>
<td width="56"><font size="2"><%=rs("Project")%> </font></td>
<td width="74"><font size="2"><%=rs("Model")%> </font></td>
<td width="175"><font size="2"><%=rs("Description")%> </font></td>
<td width="115"><font size="2"><%=rs("Effective_Date")%> </font></td>
<td width="113"><font size="2"><%=rs("Obsolete_Date")%> </font></td>
<td width="24"><font size="2"><%=rs("DMR")%> </font></td>
<td width="62"><font size="2"><a href="updoc.asp?ID=<%=rs("ID")%>">Modify</a></font></td>
<td width="59" ><font size="2">Save as</font></td>
<td ><font size="2" onclick="return del()"><input type=hidden name=id value="<%=request("id")%>"><a href="editdoc.asp?ID=<%=rs("ID")%>">Delete</a></font></td>
</tr>
<%rs.MoveNext
if rs.eof then exit for
next%>


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


<tr>
<td height="51"><img src="images/copyright.jpg" width="990" height="51" ></td>
</tr>

</table>

</form>

</body>

</html>
...全文
221 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
toury 2008-12-03
  • 打赏
  • 举报
回复
把getdocno/getrev/getproject/page这几个变量放到[下一页]等链接的URL参数中去,例如:
<a href="aaa.asp?id=<%=id%>&getdocno=<%=getdocno%>&getrev=<%=getrev%>&getproject=<%=getproject%>&page=<%=page%>">[下一页]</a>

红字是你原来的参数
sy_binbin 2008-12-03
  • 打赏
  • 举报
回复
查询条件没带到翻页的链接里
http://topic.csdn.net/u/20081203/01/a9856aac-cbbf-4efd-99f4-fe6ae5a40621.html

你看看我在这个帖子里的回答吧
rollin5460 2008-12-03
  • 打赏
  • 举报
回复
大家帮帮忙呀。
rollin5460 2008-12-03
  • 打赏
  • 举报
回复
怎么没人理我呀
rollin5460 2008-12-03
  • 打赏
  • 举报
回复
在第二页或其它页面(第一页除外)的查询条件中输入查询条件,地址栏的参数好像还是以前的。没得到更改之后的查询条件。
rollin5460 2008-12-03
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 rollin5460 的回复:]
参数好像能传过去,但是点我点击的时候跳转就不对了。我的分页函数如下,请大家帮我看看。

<%PageBreak Page,"editdoc.asp?docno="&getdocno&"&rev="&getrev&"&project="&getproject&"&",rs%>



<%
Sub PageBreak(Page,url,rs) '分页函数
Page=CInt(Page)
pc=rs.PageCount
If Instr(url,"?") <=0 Then url=url & "?"
If Page < 1 Then Page=1
If Page >= pc Then Page=pc
If Page <> 1 Then
Respons…
[/Quote]
我是这样调用的,如果我在第二页改变查询条件,就得不到正确的结果集。在第一页改没有问题,请大家帮我看看。
cxbase 2008-12-03
  • 打赏
  • 举报
回复
对不起,有一个笔误,更正一下:
Rs.pagesize = 10 ‘分页页面的记录数量
Rs.absoultepage = pageTo ’分页页面记录集的绝对位置
cxbase 2008-12-03
  • 打赏
  • 举报
回复
楼主试试我的这个方法:
<%
查询条件=request("查询条件")

'取分页的页号
if cint(request("page")) = 0 then
pageTo = 1
else
pageTo = CInt(request("page"))
endif

set rs = server.createobject("adodb.recordset")
rs.open "你的查询字符串",conn,3,2
if not(rs.bof and rs.eof) then
rs.pagesize = pageTo
rs.absolutepage=你的每页的记录条数
for i=1 to rs.pagesize
'你的记录读取过程
rs.movenext
if rs.eof then exit for
next
else
response.write("没有符合条件的记录")
endif


‘分页跳转
if pageTo >2 then
<a href="网页名.asp?page=1&查询条件=<%=查询条件%>">首页</a>
<a href="网页名.asp?page=<%=pageTo-1%>&查询条件=<%=查询条件%>">上一页</a>
else
首页  上一页
end if


if pageTo > rs.pagecount-1 then
<a href="网页名.asp?page=<%=pageTo+1%>&查询条件=<%=查询条件%>">下一页</a>
<a href="网页名.asp?page=<%=rs.pagecount%>&查询条件=<%=查询条件%>">尾页</a>
else
下一  页尾页
end if

%>
rollin5460 2008-12-03
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 toury 的回复:]
引用 8 楼 rollin5460 的回复:
嗯,可以了。谢谢!但是又冒出一新问题,当我选定一条件后,得到正确的记录,但是当我改变查询条件时为什么也是之前的那个结果集呀。

<select size="1" name="getproject">--->加上红字
<select size="1" name="getproject" onchange="javascript:document.myform.submit();">
[/Quote]

这种方法好像不行。我现在查询的第一页改条件可以得到正确的结果。但是如果我到第二页去改查询条件,查询条件好像改变不了,所以也得不到结果集,请大家帮帮忙看我要怎么处理呢。
toury 2008-12-03
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 rollin5460 的回复:]
嗯,可以了。谢谢!但是又冒出一新问题,当我选定一条件后,得到正确的记录,但是当我改变查询条件时为什么也是之前的那个结果集呀。
[/Quote]
<select size="1" name="getproject">--->加上红字
<select size="1" name="getproject" onchange="javascript:document.myform.submit();">
toury 2008-12-03
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 rollin5460 的回复:]
嗯,可以了。谢谢!但是又冒出一新问题,当我选定一条件后,得到正确的记录,但是当我改变查询条件时为什么也是之前的那个结果集呀。
[/Quote]
<select size="1" name="getproject" onchange="javascript:document.myform.submit();">
virgo2008 2008-12-03
  • 打赏
  • 举报
回复
你在点击下一页的时候有没有传参数呢?
rollin5460 2008-12-03
  • 打赏
  • 举报
回复
是呀,我现在如果换条件的话得到的结果集也是之前的结果集。
virgo2008 2008-12-03
  • 打赏
  • 举报
回复
重新换条件的时候你又获取新的条件做查询条件吗?
rollin5460 2008-12-03
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 rollin5460 的回复:]
嗯,可以了。谢谢!但是又冒出一新问题,当我选定一条件后,得到正确的记录,但是当我改变查询条件时为什么也是之前的那个结果集呀。
[/Quote]

大家帮忙看看怎么回事呀。谢谢啦!
CaptainGan 2008-12-03
  • 打赏
  • 举报
回复
可能是你的在开始的代码没有关闭数据库连接。
CaptainGan 2008-12-03
  • 打赏
  • 举报
回复
好像是ASP,如果是的话,那么就使用DataList或者是DataGrad,这两种都有自带的实现分页的功能,将数据库中的数据读到两个表格中就是了,自定义设置分页。就是了简单,何必使用数据库来实现分页。太麻烦了。
还有就是你这种功能实现代码和网页代码和在一起很不好,最好还是分开将网页代码和功能代码分开好,便于调试。
rollin5460 2008-12-03
  • 打赏
  • 举报
回复
请大家帮帮我哦
rollin5460 2008-12-03
  • 打赏
  • 举报
回复
嗯,可以了。谢谢!但是又冒出一新问题,当我选定一条件后,得到正确的记录,但是当我改变查询条件时为什么也是之前的那个结果集呀。
toury 2008-12-03
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 rollin5460 的回复:]
当我设置查询条件时,只有当前页得到正确的结果,也可以得到正确的page,但是我下一页的时候就出问题了。
[/Quote]
对呀,因为下一页中requst("getdocno")不存在啊,你的参数传的是docno,还有其他两个也是
加载更多回复(3)

28,391

社区成员

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

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