标题:[求助]asp搜索后再分页 如何把搜索条件的sql传过去[已解决]
只看楼主
madpbpl
Rank: 4
等 级:贵宾
威 望:11
帖 子:2876
专家分:244
注 册:2007-4-5
结帖率:100%
 问题点数:0 回复次数:8 
[求助]asp搜索后再分页 如何把搜索条件的sql传过去[已解决]
我对搜索出来的页面进行分页,根据搜索条件不同进来了判断,如下:
if ...
sql =...
elseif ...
sql =
elseif ...
sql =...
如此这样,然后进行分页时如何把sql传进去呢?
<a href="search.asp?page=<%=currentpage+1%>想在这把sql插进来,不知道思路是否正确">下一页</a>
ps:不把sql传进来,搜索时是正确的,点击下一页,上一页等链接时会出错,请问应该如何设置呢?

[此贴子已经被作者于2007-5-22 20:20:02编辑过]

搜索更多相关主题的帖子: sql asp 搜索 条件 
2007-05-22 14:39
阳光白雪
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:39
帖 子:2220
专家分:0
注 册:2005-11-18
得分:0 

<%
Dim SearchStr
SearchStr = ""
If KeyWord1 <> "" Then
Sql = ...
SearchStr = SearchStr &"&KeyWord1="& KeyWord1
ElseIf KeyWord2 <> "" Then
Sql = ...
SearchStr = SearchStr &"&KeyWord2="& KeyWord2
...
End IF

%>
<a href="search.asp?page=<%=currentpage+1%><%=SearchStr%>想在这把sql插进来,不知道思路是否正确">下一页</a>


专注于WEB前端交互平台开发:[url=http://blog./]blog.[/url](富客户端技术(RIA)交流平台)
2007-05-22 15:01
發呆的小猪
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:362
专家分:0
注 册:2006-10-10
得分:0 
&lt;a href="search.asp?变量=&lt;%=值%&gt;&amp;page=&lt;%=page%&gt;"&gt;下一页&lt;/a&gt;把值传过去就行了

营口小猪 http://bbs.
2007-05-22 15:13
madpbpl
Rank: 4
等 级:贵宾
威 望:11
帖 子:2876
专家分:244
注 册:2007-4-5
得分:0 
首先感谢楼上2位的帮助,谢谢!
怪我没有把问题表达清楚,具体的sql如下:
有三个下拉框选择和一个关键字表单,如果都不选则选则列出表中所有数据,如果只选择下拉框,不填关键字,则选择符合所选下拉框的数据,如果下拉框和关键字都选择则选择两者条件都满足的数据
下面是我的想法:
if cq="" and zb="" and price="" and key="" then
sql ="select * from places order by id desc"
elseif (cq<>"" and key="") or (zb<>"" and key="") or (price<>"" and key="") then
sql ="select * from places where cq like '%" & cq & "%' and zb like '%" & zb & "%' and price like '%" & price & "%' order by id desc"
else if key<>""
sql = ="select * from places where cq like '%" & cq & "%' and zb like '%" & zb & "%' and price like '%" & price & "%' and name like '%" & key & "%'......order by id desc"
name:数据库中其他的字段,还有n个没有列出
是在这种情况下搜索,然后进行分页的,搜索没有问题,但是进行分页时出现的问题。



2007-05-22 15:47
guyer
Rank: 2
等 级:新手上路
威 望:5
帖 子:451
专家分:0
注 册:2007-1-19
得分:0 

这个是我以前写的一个 不知道你能不能用 我这个是2个列表 一个关键字的,比较简单的.

<!--#include file="conn.inc"-->
<!--#Include file="admin/adovbs.inc"-->

<%
rs3.open "select * from p_class where l_id=2 order by id asc",conn,1,1

%>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>-=济南雅致泰克电子有限公司=-</title>
<link href="css.css" rel="stylesheet" type="text/css">
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<%
count = 0
do while not rs3.eof
%>
subcat[<%=count%>] = new Array("<%=rs3("c_types")%>","<%=rs3("c_name")%>","<%=rs3("id")%>");
<%
count = count + 1
rs3.movenext
loop
rs3.close
%>
onecount=<%=count%>;

function changelocation(locationid)
{

document.form1.ctypes.length = 0;
//window.alert(locationid);
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.form1.ctypes.options[document.form1.ctypes.length] = new Option(subcat[i][0], subcat[i][0]);
//window.alert("aa");
}
}

}

</script>

</head>
<body>

<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><!--#include file="top.asp"--></td>
</tr>
</table>
<table width="1000" height="124" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="124" align="center" valign="top"> <table width="1000" height="302" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="23%" valign="top"><table width="100%" height="78" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><img src="images/index_r4_c1.jpg" width="233" height="53"></td>
</tr>
<tr>
<td height="178" align="left" valign="top" background="images/index_r5_c1.jpg"><div align="center">
<table width="93%" border="0" cellspacing="0" cellpadding="0">
<%
sql="select * from gqgx where notice=true Order By id desc"
set rs2=conn.execute(sql)
if rs2.eof or rs2.bof then
else
for i=1 to 11
id=rs2("id")
title=rs2("title")
titl=left(title,16)
response.Write("<tr>")
response.Write("<td align=left><A href=gqxxs.asp?id="&id&" target=_blank title="&title&">"&titl&"</a></td>")
response.Write(" </tr>")
rs2.movenext
if rs2.eof or rs2.bof then exit for
next
end if
%>


<tr>
<td><div align="right"><a href="gqxx.asp">更多>></a> </div></td>
</tr>
</table>
</div></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/index_r4_c3.jpg" width="233" height="61"></td>
</tr>
<tr>
<td height="160" align="center" valign="top" background="images/index_r8_c1.jpg"><div align="center">
<form name="form1" method="post" action="prods.asp">
产品类别:
<select name="classid" id="classid" class="unnamed1" onChange="changelocation(document.form1.classid.options[document.form1.classid.selectedIndex].value)">
<option value="0" selected>↓选择类别↓</option>
<% sql="select * from p_class where l_id=1"
set rs1=conn.Execute (sql) %>
<%dim cj
do while not rs1.EOF
id=rs1("id")
c_name=rs1("c_name")
response.Write("<option value="&c_name&">"&c_name&"</option>")
%>
<%
rs1.MoveNext
loop
rs1.close
set rs1=nothing
%>

</select>
<br>
<br>
分  类:
<select name="ctypes" id="ctypes" class="unnamed1">
<option value="0" selected>↓选择类别↓</option>
</select>
<br>
<br>
产品名称:
<input name="pname" type="text" class="unnamed2" id="pname">
<br>
<br>
<input type="submit" name="Submit" value="提交">  
<input type="reset" name="Submit2" value="重置">
</form>
</div></td>
</tr>
</table></td>
<td width="77%" valign="top"><table width="100%" height="450" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="59"><img src="images/chanpin.jpg" width="765" height="59"></td>
</tr>
<tr>
<td height="361" align="left" valign="top">

<br><%
if request("classid")="0" then
pname=request("pname")
str="select * from prod where title like '%"&pname&"%' Order By id desc"
a="&classid=0&pname="&pname
elseif request("pname")<>"" or request("classid")<>"0" then
pname=request("pname")
classid=request("classid")
ctypes=request("ctypes")
str="select * from prod where title like '%"&pname&"%' and c_name='"&classid&"' and c_types='"&ctypes&"' Order By id desc"
a="&classid="&classid&"&ctypes="&ctypes&"&pname="&pname
else
str="select * from prod Order By id desc"
a=""
end if
rs.cursortype=3
rs.open str,conn,3,1
if rs.eof or rs.bof then
response.write "没有信息记录"
else
rs.pagesize=8
nums=rs.pagecount

i=0
if request("page")="" then
page=1
else
page=CLng(request("page"))
end if

IF page<1 Then
page=1
end if
If page>nums Then
page=nums
rs.absolutepage=page
end if
rs.absolutepage=cint(page)%>
<table width="90%" height="258" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<% do while not rs.eof%>

<td height="125" align="left" valign="top">
<table width="360" border="0" align="left" cellpadding="0" cellspacing="0" bgcolor="ffffff">
<tr>
<td width="360" height="190" align="center" valign="middle" background="images/pbg.jpg">
<% if trim(rs("photo"))<>"" then %>
<img src=admin/<% = trim(rs("photo"))%> width="320" height="160" border=0 >
<% else %>
<img src=images/emptybook.jpg border=0 >
<% end if %></td>
</tr>
<tr>
<td height="20" align="center"><a href=productwz.asp?id=<%=rs("id")%> target="_blank"><%=rs("title")%></a> </td>
</tr>
</table>
</td>
<%
i=i+1
if i mod 2=0 then response.write("</tr><tr>")
if i>=8 then Exit Do
rs.movenext
loop
rs.close
set rs=nothing
end if
%>
</tr>
</table>
<br>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="20"><div align="center">
<table width="330" border="0" align="center" bgcolor="#FFFFFF">
<tr>
<%
'翻页控制代码
IF page<>1 Then
Response.Write("<td><a href=prods.asp?page=1"&a&"><font color=000000>第一页</font></a></td>")
Response.Write("<td><a href=prods.asp?page="&(page-1)&""&a&"><font color=000000>上一页</font></a></td>")
Else
Response.Write("<td>第一页</td>")
Response.Write("<td>上一页</td>")
End IF
IF page<>nums then
Response.Write("<td><a href=prods.asp?page=" & (page+1) & ""&a&"><font color=000000>下一页</font></a></td>")
Response.Write("<td><a href=prods.asp?page=" & nums & ""&a&"><font color=000000>最后一页</font></a></td>")
Else
Response.Write("<td>下一页</td>")
Response.Write("<td>最后一页</td>")
End IF
%>
<td><span class=style22>共<%=nums%>页</span></td>
<td align="left"><span class=style22>当前第<%=page%>页</span></td>
</tr>
</table>
</div></td>
</tr>
</table>
<br>
</td>
</tr>
</table></td>
</tr>
</table></td></tr>
</table>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><!--#include file="bon.asp"--></td>
</tr>
</table>
</body>
</html>



http://www./
2007-05-22 15:54
madpbpl
Rank: 4
等 级:贵宾
威 望:11
帖 子:2876
专家分:244
注 册:2007-4-5
得分:0 
谢谢guyer,看了你的程序,调整了一下,还是没有解决问题。
你的思路和阳光白雪的思路基本上是一样的,我试着把sql传进去后,搜索时还是不只对搜索结果分页,而是对整个表进行分页,再去想想办法。

[此贴子已经被作者于2007-5-22 18:29:45编辑过]

2007-05-22 17:57
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
得分:0 
传Sesssion只能是临时的解决办法,最好的方法应该是传参数。
2007-05-22 19:06
madpbpl
Rank: 4
等 级:贵宾
威 望:11
帖 子:2876
专家分:244
注 册:2007-4-5
得分:0 
非常感谢阳光白雪和guyer的帮助,你们的说法是对的,是我刚才调试错了,用你们的方法已经解决问题
2007-05-22 19:10
madpbpl
Rank: 4
等 级:贵宾
威 望:11
帖 子:2876
专家分:244
注 册:2007-4-5
得分:0 
接受yms的建议,我用了阳光白雪的方法,同时也借签了guyer的程序
if cq="" and zb="" and price="" and key="" then
sql ="select * from places order by id desc"
SearchStr = SearchStr &"&cq="&cq&"&zb="&zb&"&price="&price

elseif (cq<>"" and key="") or (zb<>"" and key="") or (price<>"" and key="") then
sql ="select * from places where cq like '%" & cq & "%' and zb like '%" & zb & "%' and price like '%" & price & "%' order by id desc"
SearchStr = SearchStr &"&cq="&cq&"&zb="&zb&"&price="&price

else if key<>""
sql ="select * from places where cq like '%" & cq & "%' and zb like '%" & zb & "%' and price like '%" & price & "%' and name like '%" & key & "%'......order by id desc"
SearchStr = SearchStr &"&cq="&cq&"&zb="&zb&"&price="&price&"key="&key

<a href="search.asp?page=<%=currentpage+1%> <%=SearchStr%> ">下一页</a>
把红色部份插到每个链接处,就解决问题了。

2007-05-22 20:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-141491-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.088005 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved