asp 分页中显示不正常
加了一多条件自由选择,在三个条件中任意输入可查询,但是加了个分页后,点击下一页后,SQL执行语句不再有任何限制,表中数据全显示,加"Response.writesql"查...
加了一多条件自由选择,在三个条件中任意输入可查询,但是加了个分页后,点击下一页后,SQL执行语句不再有任何限制,表中数据全显示,加"Response.write sql "查询时是"select * from student where [培训时间]='2008-11-17'",但是一点下一页就成了"select * from student"
这应该怎么解决呢?
代码如下
<!--#include virtual="/Connections/conn.asp" -->
<%
dim s1,s2,s3,sql,rs
s1= Trim(Request.Form("培训学生"))
s2= Trim(Request.Form("培训成绩"))
s3= Trim(Request.Form("培训时间"))
sql="select * from student"
if s1<>"" and s2<>"" and s3<>"" then
sql=sql+" where [培训学生]='"&s1&"' and [培训成绩]='"&s2&"' and [培训时间]='"&s3&"'"
end if
if s1<>"" and s2 <> "" and s3="" then
sql=sql+" where [培训学生]='"&s1&"' and [培训成绩]='"&s2&"' "
end if
if s1<>"" and s2 = "" and s3="" then
sql=sql+" where [培训学生]='"&s1&"'"
end if
if s1="" and s2 <> "" and s3<>"" then
sql=sql+" where [培训成绩]='"&s2&"' and [培训时间]='"&s3&"'"
end if
if s1="" and s2 = "" and s3<>"" then
sql=sql+" where [培训时间]='"&s3&"'"
end if
if s1<>"" and s2 = "" and s3<>"" then
sql=sql+" where [培训学生]='"&s1&"' and [培训时间]='"&s3&"'"
end if
if s1="" and s2 <> "" and s3="" then
sql=sql+" where [培训成绩]='"&s2&"'"
end if
set rs=server.createobject("adodb.recordset")
Response.write sql
rs.open sql,conn,1,3
rs.pagesize=3
page=request("page")
if page="" then page=1
if cint(page)<="0" then page=1
if cint(page)>rs.pagecount then page=rs.pagecount
if not rs.eof then rs.absolutepage=cint(page)
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<table width="600" border="1" align="center">
<tr>
<td colspan="5">按姓名查询结果如下:</td>
</tr>
<tr>
<td>序列</td>
<td>培训学生</td>
<td>培训成绩</td>
<td>培训老师</td>
<td>培训时间</td>
</tr>
<%
for i=0 to rs.pagesize-1
if rs.bof or rs.eof then exit for
%>
<tr>
<td><%=(rs.Fields.Item("编号").Value)%></td>
<td><%=(rs.Fields.Item("培训学生").Value)%></td>
<td><%=(rs.Fields.Item("培训成绩").Value)%></td>
<td><%=(rs.Fields.Item("培训老师").Value)%></td>
<td><%=(rs.Fields.Item("培训时间").Value)%></td>
</tr>
<%
rs.movenext()
next
%>
<tr>
<td colspan="2"><A HREF="query_s_name.asp?page=<%=cint(page)-1%>">上一页</A></td>
<td><%response.write("记录总数:"&rs.RecordCount)%></td>
<td colspan="2"><A HREF="query_s_name.asp?page=<%=cint(page)+1%>">下一页</A></td>
</tr>
</table>
</body>
</html>
<%
rs.Close()
Set rs = Nothing
%>
wdzahyqs:
问题依旧,还是那个样子,是多条件查询方式不对?还是这种查询方式与这种分页不合??
candy030203:
问题依然是先前那样.还在郁闷的查找原因中~~
forteensay:
如果where 1=1 那么条件不就成了恒等了?按你意思也改了,并没有解决这个问题。
给行政部的做一个简单的培训记录系统,这个问题一直没得到解决,还在不停的寻求答案中。 展开
这应该怎么解决呢?
代码如下
<!--#include virtual="/Connections/conn.asp" -->
<%
dim s1,s2,s3,sql,rs
s1= Trim(Request.Form("培训学生"))
s2= Trim(Request.Form("培训成绩"))
s3= Trim(Request.Form("培训时间"))
sql="select * from student"
if s1<>"" and s2<>"" and s3<>"" then
sql=sql+" where [培训学生]='"&s1&"' and [培训成绩]='"&s2&"' and [培训时间]='"&s3&"'"
end if
if s1<>"" and s2 <> "" and s3="" then
sql=sql+" where [培训学生]='"&s1&"' and [培训成绩]='"&s2&"' "
end if
if s1<>"" and s2 = "" and s3="" then
sql=sql+" where [培训学生]='"&s1&"'"
end if
if s1="" and s2 <> "" and s3<>"" then
sql=sql+" where [培训成绩]='"&s2&"' and [培训时间]='"&s3&"'"
end if
if s1="" and s2 = "" and s3<>"" then
sql=sql+" where [培训时间]='"&s3&"'"
end if
if s1<>"" and s2 = "" and s3<>"" then
sql=sql+" where [培训学生]='"&s1&"' and [培训时间]='"&s3&"'"
end if
if s1="" and s2 <> "" and s3="" then
sql=sql+" where [培训成绩]='"&s2&"'"
end if
set rs=server.createobject("adodb.recordset")
Response.write sql
rs.open sql,conn,1,3
rs.pagesize=3
page=request("page")
if page="" then page=1
if cint(page)<="0" then page=1
if cint(page)>rs.pagecount then page=rs.pagecount
if not rs.eof then rs.absolutepage=cint(page)
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<table width="600" border="1" align="center">
<tr>
<td colspan="5">按姓名查询结果如下:</td>
</tr>
<tr>
<td>序列</td>
<td>培训学生</td>
<td>培训成绩</td>
<td>培训老师</td>
<td>培训时间</td>
</tr>
<%
for i=0 to rs.pagesize-1
if rs.bof or rs.eof then exit for
%>
<tr>
<td><%=(rs.Fields.Item("编号").Value)%></td>
<td><%=(rs.Fields.Item("培训学生").Value)%></td>
<td><%=(rs.Fields.Item("培训成绩").Value)%></td>
<td><%=(rs.Fields.Item("培训老师").Value)%></td>
<td><%=(rs.Fields.Item("培训时间").Value)%></td>
</tr>
<%
rs.movenext()
next
%>
<tr>
<td colspan="2"><A HREF="query_s_name.asp?page=<%=cint(page)-1%>">上一页</A></td>
<td><%response.write("记录总数:"&rs.RecordCount)%></td>
<td colspan="2"><A HREF="query_s_name.asp?page=<%=cint(page)+1%>">下一页</A></td>
</tr>
</table>
</body>
</html>
<%
rs.Close()
Set rs = Nothing
%>
wdzahyqs:
问题依旧,还是那个样子,是多条件查询方式不对?还是这种查询方式与这种分页不合??
candy030203:
问题依然是先前那样.还在郁闷的查找原因中~~
forteensay:
如果where 1=1 那么条件不就成了恒等了?按你意思也改了,并没有解决这个问题。
给行政部的做一个简单的培训记录系统,这个问题一直没得到解决,还在不停的寻求答案中。 展开
4个回答
展开全部
试试这个,如果是SQL数据库请把 # 改为 '
培训成绩应是数字型的,所以 S2 的左右的 '去掉.
<!--#include virtual="/Connections/conn.asp" -->
<%
dim s1,s2,s3,sql,rs
s1= Trim(Request("培训学生"))
s2= Trim(Request("培训成绩"))
s3= Trim(Request("培训时间"))
if s1="" then s1=Trim(Request("s1"))
if s2="" then s2= Trim(Request("s2"))
if s3="" then s3=Trim(Request("s3"))
sql="select * from student"
if s1<>"" and s2<>"" and s3<>"" then
sql=sql & " where s_student='"&s1&"' and s_result="&s2&" and s_time=#"&s3&"#"
end if
if s1<>"" and s2 <> "" and s3="" then
sql=sql & " where s_student='"&s1&"' and s_result="&s2&" "
end if
if s1<>"" and s2 = "" and s3="" then
sql=sql & " where s_student='"&s1&"'"
end if
if s1="" and s2 <> "" and s3<>"" then
sql=sql & " where s_result="&s2&" and s_time=#"&s3&"#"
end if
if s1="" and s2 = "" and s3<>"" then
sql=sql & " where s_time=#"&s3&"#"
end if
if s1<>"" and s2 = "" and s3<>"" then
sql=sql & " where s_student='"&s1&"' and s_time=#"&s3&"#"
end if
if s1="" and s2 <> "" and s3="" then
sql=sql & " where s_result="&s2&""
end if
set rs=server.createobject("adodb.recordset")
Response.write sql
rs.open sql,conn,1,3
rs.pagesize=3
page=request("page")
if page="" then page=1
if cint(page)<="0" then page=1
if cint(page)>rs.pagecount then page=rs.pagecount
if not rs.eof then rs.absolutepage=cint(page)
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<table width="600" border="1" align="center">
<tr>
<td colspan="5">按姓名查询结果如下:</td>
</tr>
<tr>
<td>序列</td>
<td>培训学生</td>
<td>培训成绩</td>
<td>培训老师</td>
<td>培训时间</td>
</tr>
<%
for i=0 to rs.pagesize-1
if rs.bof or rs.eof then exit for
%>
<tr>
<td><%=(rs.Fields.Item("编号").Value)%></td>
<td><%=(rs.Fields.Item("培训学生").Value)%></td>
<td><%=(rs.Fields.Item("培训成绩").Value)%></td>
<td><%=(rs.Fields.Item("培训老师").Value)%></td>
<td><%=(rs.Fields.Item("培训时间").Value)%></td>
</tr>
<%
rs.movenext()
next
%>
<tr>
<td colspan="2"><A HREF="query_s_name.asp?page=<%=cint(page)-1%>&s1=<%=s1%>&s2=<%=s2%>&s3=<%=s3%>">上一页</A></td>
<td><%response.write("记录总数:"&rs.RecordCount)%></td>
<td colspan="2"><A HREF="query_s_name.asp?page=<%=cint(page)+1%>&s1=<%=s1%>&s2=<%=s2%>&s3=<%=s3%>">下一页</A></td>
</tr>
</table>
</body>
</html>
<%
rs.Close()
Set rs = Nothing
%>
培训成绩应是数字型的,所以 S2 的左右的 '去掉.
<!--#include virtual="/Connections/conn.asp" -->
<%
dim s1,s2,s3,sql,rs
s1= Trim(Request("培训学生"))
s2= Trim(Request("培训成绩"))
s3= Trim(Request("培训时间"))
if s1="" then s1=Trim(Request("s1"))
if s2="" then s2= Trim(Request("s2"))
if s3="" then s3=Trim(Request("s3"))
sql="select * from student"
if s1<>"" and s2<>"" and s3<>"" then
sql=sql & " where s_student='"&s1&"' and s_result="&s2&" and s_time=#"&s3&"#"
end if
if s1<>"" and s2 <> "" and s3="" then
sql=sql & " where s_student='"&s1&"' and s_result="&s2&" "
end if
if s1<>"" and s2 = "" and s3="" then
sql=sql & " where s_student='"&s1&"'"
end if
if s1="" and s2 <> "" and s3<>"" then
sql=sql & " where s_result="&s2&" and s_time=#"&s3&"#"
end if
if s1="" and s2 = "" and s3<>"" then
sql=sql & " where s_time=#"&s3&"#"
end if
if s1<>"" and s2 = "" and s3<>"" then
sql=sql & " where s_student='"&s1&"' and s_time=#"&s3&"#"
end if
if s1="" and s2 <> "" and s3="" then
sql=sql & " where s_result="&s2&""
end if
set rs=server.createobject("adodb.recordset")
Response.write sql
rs.open sql,conn,1,3
rs.pagesize=3
page=request("page")
if page="" then page=1
if cint(page)<="0" then page=1
if cint(page)>rs.pagecount then page=rs.pagecount
if not rs.eof then rs.absolutepage=cint(page)
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<table width="600" border="1" align="center">
<tr>
<td colspan="5">按姓名查询结果如下:</td>
</tr>
<tr>
<td>序列</td>
<td>培训学生</td>
<td>培训成绩</td>
<td>培训老师</td>
<td>培训时间</td>
</tr>
<%
for i=0 to rs.pagesize-1
if rs.bof or rs.eof then exit for
%>
<tr>
<td><%=(rs.Fields.Item("编号").Value)%></td>
<td><%=(rs.Fields.Item("培训学生").Value)%></td>
<td><%=(rs.Fields.Item("培训成绩").Value)%></td>
<td><%=(rs.Fields.Item("培训老师").Value)%></td>
<td><%=(rs.Fields.Item("培训时间").Value)%></td>
</tr>
<%
rs.movenext()
next
%>
<tr>
<td colspan="2"><A HREF="query_s_name.asp?page=<%=cint(page)-1%>&s1=<%=s1%>&s2=<%=s2%>&s3=<%=s3%>">上一页</A></td>
<td><%response.write("记录总数:"&rs.RecordCount)%></td>
<td colspan="2"><A HREF="query_s_name.asp?page=<%=cint(page)+1%>&s1=<%=s1%>&s2=<%=s2%>&s3=<%=s3%>">下一页</A></td>
</tr>
</table>
</body>
</html>
<%
rs.Close()
Set rs = Nothing
%>
展开全部
要在上一页和下一页的连接地方。加入索引..
1.
把s1= Trim(Request.Form("培训学生"))
s2= Trim(Request.Form("培训成绩"))
s3= Trim(Request.Form("培训时间"))
改为
s1= Trim(Request("培训学生"))
s2= Trim(Request("培训成绩"))
s3= Trim(Request("培训时间"))
2.在<A HREF="query_s_name.asp?page=<%=cint(page)-1%>">和<A HREF="query_s_name.asp?page=<%=cint(page)+1%>">加入如下代码
&s1=<%=s1%>&s2=<%=s2%>&s3=<%=s3%>
完成代码:<A HREF="query_s_name.asp?page=<%=cint(page)-1%>&s1=<%=s1%>&s2=<%=s2%>&s3=<%=s3%>">
<A HREF="query_s_name.asp?page=<%=cint(page)+1%>>&s1=<%=s1%>&s2=<%=s2%>&s3=<%=s3%>">
你可以试试
1.
把s1= Trim(Request.Form("培训学生"))
s2= Trim(Request.Form("培训成绩"))
s3= Trim(Request.Form("培训时间"))
改为
s1= Trim(Request("培训学生"))
s2= Trim(Request("培训成绩"))
s3= Trim(Request("培训时间"))
2.在<A HREF="query_s_name.asp?page=<%=cint(page)-1%>">和<A HREF="query_s_name.asp?page=<%=cint(page)+1%>">加入如下代码
&s1=<%=s1%>&s2=<%=s2%>&s3=<%=s3%>
完成代码:<A HREF="query_s_name.asp?page=<%=cint(page)-1%>&s1=<%=s1%>&s2=<%=s2%>&s3=<%=s3%>">
<A HREF="query_s_name.asp?page=<%=cint(page)+1%>>&s1=<%=s1%>&s2=<%=s2%>&s3=<%=s3%>">
你可以试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
page=request("page") 应该是 request.QueryString("page")
如果是用form表单提交数据,那么获取数据就应该是request.Form("")
如果只是传输了单独的字符串,类似于...get.asp?id=3,就用request.QueryString("") 获取id的具体的值。
采用表单提交 就要有类似
<form id="" name="" method="post" action="">
<input name="" id="" type="text" />
<input name="" type="reset" value="重置" />
<input name="" type="submit" value="提交" />
</form>
表单内容
如果是用form表单提交数据,那么获取数据就应该是request.Form("")
如果只是传输了单独的字符串,类似于...get.asp?id=3,就用request.QueryString("") 获取id的具体的值。
采用表单提交 就要有类似
<form id="" name="" method="post" action="">
<input name="" id="" type="text" />
<input name="" type="reset" value="重置" />
<input name="" type="submit" value="提交" />
</form>
表单内容
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
sql="select * from student"
加一个 select * from student where 1=1
后面的 sql=sql+" and 条件"
加一个 select * from student where 1=1
后面的 sql=sql+" and 条件"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询