标题:求助:制作asp+access数据库多条件搜索条
取消只看楼主
cwang2100
Rank: 2
等 级:论坛游民
帖 子:12
专家分:12
注 册:2010-3-16
结帖率:100%
已结贴  问题点数:20 回复次数:1 
求助:制作asp+access数据库多条件搜索条
我是菜鸟,想学一下ASP语言,请大家多多帮忙啊!!!

我的access数据库是data.mdb,表是tade,字段有五个:

id(自动编码)   aa(产品名称)   bb(省份)  cc(价格/斤)     dd(级别)

   1             花生          广东省      6.00元        一级

   2             花生          广西省      5.00元        三级

   3             花生油        广西省      8.00元        二级

搜索条如下图:



aa为关键词搜索,可以加其它三个的任意一个组合或全部条件组合查询,这个功能怎么实现啊??
下面代码单一关键词搜索就可以了但其它功能一起就搞不掂了.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件</title>
</head>
<body bgcolor="#ffffff">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<script>
function btn_ck_bh_Click()
{
var cx = document.form1.cxsj.value;
form1.action ="sou.asp?cx="+cx;
}

</script>
<table width=690 border="0" cellspacing="0"  bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF"  
width="100%" style="word-break:break-all" align="center">
<tr>
<td width="580" align="center" colspan="7">
<form method="POST" name="form1" action=sou.asp>
<P><font style="font-size: 14px " color="0000ff"  align="left">搜索内容</font><input type="text"  
name="cxsj" size="15">  

<select name="bb" id="Searc_bb">
    <option selected="selected" value="">所在属省份</option>
    <option value="广东">广东</option>
    <option value="广西">广西</option>
</select>
        
        <select name="dd" id="Search_dd">
    <option selected="selected" value="">按等级</option>
    <option value="10001">一级</option>
    <option value="251">二级</option>   
         <option value="250">三级</option>

</select> <select name="SearchUC" id="Search_UC">
    <option selected="selected" value="">默认排序</option>
    <option value="251">按价格从低到高</option>
    <option value="99999991">等级从高到低</option>
        <option value="250">按价格从高到低</option>
</select><input type="submit" value="本站搜索" name="B1" LANGUAGE="javascript" onclick="btn_ck_bh_Click
()">
</form>  
</tr>
</table>

<TABLE width=890  bgColor=#FFFFFF border=0 bordercolor="0" align="center">
<TR>
<TD>

<%
cx = request("cx")
dim pageCount
page = cint(request("page"))
set conn=server.createobject("adodb.connection")'
set rs=server.createobject("adodb.recordset")
conn.open "DBQ=" & server.mappath("data.mdb") & ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"

if cx <> "" then
sql = "select * from tade where aa like '%"&cx& "%'order by id desc"
else
sql ="select * from tade  order by id desc"
end if
rs.open sql,conn,3,3
 
if rs.bof then
errmsg=errmsg+"<br>"+"<li>"+keyword+"没有记录,请返回!!"
response.write errmsg
response.end
end if

RS.PageSize=8
pageCount = cint(rs.pageCount)
 
if page = 0 then
page =1
end if
RS.AbsolutePage = page
x=1

WHILE NOT RS.EOF AND NumRows<RS.PageSize
%>

<tr>

<td width="160">

<div align="center"><a   target="_blank"  href="<%=rs("aa")%>">
                  
</td>
</tr></div>
</table></div>

   
<%RS.MoveNext
NumRows=NumRows+1
WEND%>
<tr onmouseover="this.bgColor='#99ccff'" onmouseout="this.bgColor=''">
<td width="105%" align="center" colspan="6"> </td> </tr>
<tr>
<td width="105%" align="center" colspan="6">
<p align="center"><FONT color=#333333>共<%=PageCount%>页 第<%=page%>页★
<%if page=1 then%>首页<%end if%>
<%if page>1 then%>
<A HREF="sou.asp?page=1&cx=<%=cx%>"> 首页</A>
<%end if%>★
<%if page>1 then%><A HREF="sou.asp?page=<%=page-1%>&cx=<%=cx%>"><%end if%>上一页</a>
<%
dim pagewhere
dim p
p = 1
'pagewhere = cint(request("pagewhere"))
pagewhere = pageCount
if pagewhere>0 then
for p=1 to pagewhere
if p <> page then%>
<A HREF="sou.asp?page=<%=p%>&cx=<%=cx%>"><%=p%></a>
<%end if
if p =page then%>
<%=p%>
<% end if
next
end if%>
<%if page < PageCount then%>
<A HREF="sou.asp?page=<%=page+1%>&cx=<%=cx%>">
<%end if %>下一页</A>★
<%if page=PageCount then%>尾页
<%end if%>
<%if page<PageCount then%>
<A HREF="sou.asp?page=<%=PageCount%>&cx=<%=cx%>"> 尾页</A>
<%end if%>
</p></FONT></td> </tr> <tr>
<td width="105%" align="center" colspan="6">搜索内容:<%=cx%></td>
</tr>
</table></center></div>
</body></html>
<%
rs.close
Set rs=nothing
conn.close
set conn=nothing
%>
搜索更多相关主题的帖子: 条件 搜索 数据库 asp access 
2010-03-17 05:08
cwang2100
Rank: 2
等 级:论坛游民
帖 子:12
专家分:12
注 册:2010-3-16
得分:0 
谢谢二楼的帮助。。试试
2010-03-17 18:10



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




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

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