求教ASP查询结果分页问题,参数怎么传递啊,在线等

wzysoft 2009-02-25 09:08:15
我想做一个ASP查询子程序,但是按条件查询后显示分页的时候第一页正常,但是点下一页就出现问题了,不能显示了,要么就显示的是所有记录而不是我按条件查询的那个记录。总感觉参数传递的不对还是怎么回事,请那个高手帮我看一下。
代码所在页面为ip.asp,以下代码是其中的查询模块,



sub ipfind()
'IP查找\状态查看
call chk_login()
'权限判断
dim i,intPage,page,pre,last,filepath,sqlcx,cx_cxfs,sql
set rs = Server.CreateObject("ADODB.RecordSet")
cx_cxfs=request.Form("cxfs")
cx_cxnr=request.Form("cxnr")
select case cx_cxfs
case 1 '所有数据
sqlcx="select * from ip order by id,branch_name"
case 2 '机构查询
sqlcx="select * from ip where branch_name like '%"&request.Form("cxnr")&"%' order by id"
case 3 '部门查询
sqlcx="select * from ip where Departments like '%"&request.Form("cxnr")&"%' order by id"
case 4 '使用者查询
sqlcx="select * from ip where user_name like '%"&request.Form("cxnr")&"%' order by id"
case 5 'IP查询
sqlcx="select * from ip where ip_address like '%"&request.Form("cxnr")&"%' order by id"
case 6 'MAC查询
sqlcx="select * from ip where mac_address like '%"&request.Form("cxnr")&"%' order by id"
case 7 '未分配IP查询
'sqlcx="update ip set user_name=''"
sqlcx="select * from ip where user_name='' and ip_address<>'' order by id desc"
end select

%>
<table width="743" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><h3><img src="images/address.png" width="16" height="16"> IP地址信息
</h3></td>
</tr>
<tr>
<td><div align="center">
<form name="form2" method="post" action="ip.asp?action=ipfind">
<label>
查询方式:
<select name="cxfs" id="cxfs">
<option value="1">所有数据记录</option>
<option value="2">按机构名查询</option>
<option value="3">所属部门查询</option>
<option value="4">按使用者查询</option>
<option value="5">按IP地址查询</option>
<option value="6">MAC 地址查询</option>
<option value="7">未分配IP查询</option>
</select>
</label>
<label></label>
<label>请输入查询内容:
<input name="cxnr" type="text" id="cxnr" size="40">
</label>
<label> 
<input type="submit" name="Submit" value="查询">
</label>
</form>
</div></td>
</tr>
</table>
<%
If request.Form("cxfs")<>"" then
if session("s_rights")="" or isnull(session("s_rights"))=true then
Response.Write("<script language=javascript>alert('登录超时,请重新登录!');parent.location.href='../login.asp';</script>")
end if
rs.PageSize = 12 '这里设定每页显示的记录数
rs.CursorLocation = 3
rs.Open sqlcx,conn,0,2,1
pre = true
last = true
page = trim(Request.QueryString("page"))

if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= rs.PageCount then
intpage = rs.PageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not rs.eof then
rs.AbsolutePage = intpage
end if

if rs.eof and rs.bof then Response.Write("<script language=javascript>alert('没有找到您要找的记录,点击确定显示已分配IP记录!');location.href='ip.asp';</script>") end if
%>
<table width="743" border="1" cellpadding="0" cellspacing="0"
bordercolorlight="#000000" bordercolordark="#FFFFFF" class="set">
<tr class="top">
<td width="33">ID</td>
<td width="102">机构</td>
<td width="112">部门</td>
<td width="65">使用者</td>
<td width="160">IP地址</td>
<td width="200" align="center">操作</td>
</tr>
<!--循环开始-->
<%for i=1 to rs.PageSize
if rs.EOF or rs.BOF then exit for %>
<tr class="mid">
<td><% =rs("id")%></td>
<td><%if rs("branch_name") <> "" then%><% =rs("branch_name")%><%else%><font color="#006600"> <%end if%></td>
<td><%if rs("Departments") <> "" then%><% =rs("Departments")%><%else%><font color="#006600"> <%end if%></td>
<td><%if rs("user_name") <> "" then%><% =rs("user_name")%><%else%><font color="#006600"> <%end if%></td>
<td><%if rs("ip_address") <> "" then%><% =rs("ip_address")%><%else%><font color="#006600"> <%end if%></td>
<td align="center">
<a href="ip.asp?action=view&id=<% =rs("id")%>"> [查看]</a>
<a href="ip.asp?action=news"> [添加]</a>
<a href="ip.asp?action=edit&id=<% =rs("id")%>"> [修改]</a>
<a href="ip.asp?action=clear&id=<% =rs("id")%>"> [清空]</a>
<a href="ip.asp?action=del&id=<% =rs("id")%>"> [删除]</a>
</td>
</tr>

<%
rs.movenext
next
'wend
%>

</table>
<!--循环体结束分页部分:-->
<table width="743" border="0" cellpadding="2" cellspacing="2" borderColorLight=#808080 borderColorDark=#ffffff class="set">
<tr>
<%if rs.pagecount > 0 then%>
<td width="21%" align="center">
<p align="left">当前页<%=intpage%>/<%=rs.PageCount%> | 每页 <%=rs.PageSize%> 条记录</td>
<%else%>
<td width="16%" align="center">
<p align="left">当前页0/0</td><%end if%>
<td width="59%" align="center">
<p align="right"> <a href="ip.asp?action=ipfind&page=1">首页</a>|
<%if pre then%>
<a href="ip.asp?page=<%=intpage -1%>">上页</a>|<%end if%>
<%if last then%>
<a href=ip.asp?action=ipfind&page="<%=intpage +1%>">下页</a>|<%end if%>
<a href="ip.asp?page=<%=rs.PageCount%>">尾页</a>| 转到第
<select name="sel_page" onChange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to rs.PageCount
if i = intpage then%>
<option value="ip.asp?page=<%=i%>" selected><%=i%></option>
<%else%>
<option value="ip.asp?page=<%=i%>"><%=i%></option>
<%
end if
next
%>
</select>页 </td>
</tr>
</table>

<%
end if
end sub

...全文
126 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
楼主,能不能把你的方法和代码贴出来啊,我遇到了同样的问题,可是试试不行啊,先谢谢了。
  • 打赏
  • 举报
回复
你说的不是废话吗??

action=ipfind
不一样用
action=request("action")

吗?

你怎么这么笨?
wzysoft 2009-02-26
  • 打赏
  • 举报
回复
呵呵,谢谢楼上的兄弟,我开始把action=ipfind 直接带进去的,还有就是按照你说的做了结果没查到数据,后来把一下代码:

dim i,intPage,page,pre,last,filepath,sqlcx,cx_cxfs,sql
set rs = Server.CreateObject("ADODB.RecordSet")
cx_cxfs=request.Form("cxfs")
cx_cxnr=request.Form("cxnr")
select case cx_cxfs
case 1 '所有数据
sqlcx="select * from ip order by id,branch_name"
case 2 '机构查询
sqlcx="select * from ip where branch_name like '%"&request.Form("cxnr")&"%' order by id"
case 3 '部门查询
sqlcx="select * from ip where Departments like '%"&request.Form("cxnr")&"%' order by id"
case 4 '使用者查询
sqlcx="select * from ip where user_name like '%"&request.Form("cxnr")&"%' order by id"
case 5 'IP查询
sqlcx="select * from ip where ip_address like '%"&request.Form("cxnr")&"%' order by id"
case 6 'MAC查询
sqlcx="select * from ip where mac_address like '%"&request.Form("cxnr")&"%' order by id"
case 7 '未分配IP查询
'sqlcx="update ip set user_name=''"
sqlcx="select * from ip where user_name='' and ip_address<>'' order by id desc"
end select



放到

<table width="743" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><h3><img src="images/address.png" width="16" height="16"> IP地址信息
</h3></td>
</tr>
<tr>
<td><div align="center">
<form name="form2" method="post" action="ip.asp?action=ipfind">
<label>
查询方式:
<select name="cxfs" id="cxfs">
<option value="1">所有数据记录</option>
<option value="2">按机构名查询</option>
<option value="3">所属部门查询</option>
<option value="4">按使用者查询</option>
<option value="5">按IP地址查询</option>
<option value="6">MAC 地址查询</option>
<option value="7">未分配IP查询</option>
</select>
</label>
<label></label>
<label>请输入查询内容:
<input name="cxnr" type="text" id="cxnr" size="40">
</label>
<label> 
<input type="submit" name="Submit" value="查询">
</label>
</form>
</div></td>
</tr>
</table>


之后,终于可以,多谢了
wzysoft 2009-02-25
  • 打赏
  • 举报
回复
首先谢谢楼上几位

用cx_cxfs=request.QueryString("cxfs") 报错
用cx_cxfs=request("cxfs") 倒是没报错

然后在你这些 <a href="ip.asp?page= <%=intpage -1%>">上页 </a>改为下面形式的

<a href="ip.asp?page= <%=intpage -1%>&cxfs= <%=cx_cxfs%>&cxnr= <%=cx_cxnr%>">上页 </a>

改了以后倒是可以查询到第二页,但是不是我查询的结果,因为这些操作都在一个页面中的
sub ipfind
.....
end sub

之间,我的form post传递是<form name="form2" method="post" action="ip.asp?action=ipfind">
但是<a href="ip.asp?page= <%=intpage -1%>&cxfs= <%=cx_cxfs%>&cxnr= <%=cx_cxnr%>">上页 </a>
里面没有看到action=ipfind参数,怎么加这个参数啊?不然传递到别的页面去了
  • 打赏
  • 举报
回复
把cx_cxfs=request.Form("cxfs")
cx_cxnr=request.Form("cxnr")
改为
cx_cxfs=request("cxfs")
cx_cxnr=request("cxnr")
而不是楼上说的

不然你表单查询的时候就没有数据了


然后在你这些<a href="ip.asp?page= <%=intpage -1%>">上页 </a>改为下面形式的

<a href="ip.asp?page= <%=intpage -1%>&cxfs=<%=cx_cxfs%>&cxnr=<%=cx_cxnr%>">上页 </a>
  • 打赏
  • 举报
回复
把cx_cxfs=request.Form("cxfs")
cx_cxnr=request.Form("cxnr")
改为
cx_cxfs=request("cxfs")
cx_cxnr=request("cxnr")
而不是楼上说的

不然你表单查询的时候就没有数据了


然后在你这些<a href="ip.asp?page= <%=intpage -1%>">上页 </a>改为下面形式的

<a href="ip.asp?page= <%=intpage -1%>&cxfs=<%=cx_cxfs%>&cxnr=<%=cx_cxnr%>">上页 </a>
theZeus 2009-02-25
  • 打赏
  • 举报
回复
你用了Request.Form,而你在点上页、下页、首页、尾页的时候并不产生POST动作,所以Request.Form("cxfs")和Request.Form("cxnr")得到的值都是null,经过Select循环后sqlcx值还是空,当然出错了。

先把这两行:
cx_cxfs=request.Form("cxfs")
cx_cxnr=request.Form("cxnr")

改为:
cx_cxfs=request.QueryString("cxfs")
cx_cxnr=request.QueryString("cxnr")

然后在上页、下页、首页、尾页那些链接上的page=x后面都加上&cxfs=<%=cx_cxfs%>&cxnr=<%=cx_cxnr%>,再试一下……
wzysoft 2009-02-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 uself 的回复:]
intpage = rs.PageCount
<a href="ip.asp?page= <%=intpage -1%>">上页 </a>
<a href=ip.asp?action=ipfind&page=" <%=intpage +1%>">下页 </a>
你自己看下,上页和下页访问的可能都是固定的一页.
当然出问题了.
还有你的rs.PageCount可能也出错了.
[/Quote]

rs.PageCount 好像没有问题

<a href="ip.asp?page= <%=intpage -1%>">上页 </a>
<a href=ip.asp?action=ipfind&page=" <%=intpage +1%>">下页 </a>
这两句不一样是我测试的时候改的,首先ip.asp?action=ipfind感觉好像必须有,因为那段模块代码就是sub ipfind命名的不然参数就传不到本模块了,总感觉ip.asp?action=ipfind后面还应该带些什么参数似的
杨哥儿 2009-02-25
  • 打赏
  • 举报
回复
intpage = rs.PageCount
<a href="ip.asp?page=<%=intpage -1%>">上页</a>
<a href=ip.asp?action=ipfind&page="<%=intpage +1%>">下页</a>
你自己看下,上页和下页访问的可能都是固定的一页.
当然出问题了.
还有你的rs.PageCount可能也出错了.

28,408

社区成员

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

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