![]() |
#2
cRazy谢不清2011-06-28 08:16
|
只有本站会员才能查看附件,请 登录
附件中是我的代码,大家可以下载调试。
数据库:data.mdb
表:sell1、sell2
表sell1字段如下:
只有本站会员才能查看附件,请 登录
表sell2字段如下:
只有本站会员才能查看附件,请 登录
提交搜索关键词页面index.aps代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="Search.asp">
<table width="100%" border="0" cellspacing="2" cellpadding="3">
<tr>
<td>合同编号:<input type="text" name="xybhkey" style="width:87px;"></td>
</tr>
<tr>
<td>客户名称:<input type="text" name="mckey" style="width:87px;"></td>
</tr>
<tr>
<td>发货状态:<select name="fhztkey" style="width:87px;">
<option></option>
<option value="已发货">已发货</option>
<option value="未发货">未发货</option>
</select></td>
</tr>
<tr>
<td>产品名称:<select name="cpmckey" style="width:87px;">
<option selected="selected"></option>
<option>设备</option>
<option>配件</option>
<option>维修</option>
</select></td>
</tr>
<tr>
<td>
<input type="submit" name="Submit" value="搜索" />
<input type="reset" name="Submit2" value="清除" /></td>
</tr>
<tr>
<td height="15"></td>
</tr>
</table>
</form>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="Search.asp">
<table width="100%" border="0" cellspacing="2" cellpadding="3">
<tr>
<td>合同编号:<input type="text" name="xybhkey" style="width:87px;"></td>
</tr>
<tr>
<td>客户名称:<input type="text" name="mckey" style="width:87px;"></td>
</tr>
<tr>
<td>发货状态:<select name="fhztkey" style="width:87px;">
<option></option>
<option value="已发货">已发货</option>
<option value="未发货">未发货</option>
</select></td>
</tr>
<tr>
<td>产品名称:<select name="cpmckey" style="width:87px;">
<option selected="selected"></option>
<option>设备</option>
<option>配件</option>
<option>维修</option>
</select></td>
</tr>
<tr>
<td>
<input type="submit" name="Submit" value="搜索" />
<input type="reset" name="Submit2" value="清除" /></td>
</tr>
<tr>
<td height="15"></td>
</tr>
</table>
</form>
</body>
</html>
其中一个关键词【name="cpmckey"】是表sell2中的,而其它几个关键词在表sell1中。
查询结果显示页面search.asp代码如下:

<%
dim conn
conn="provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("data.mdb")
set cn=server.createobject("adodb.Connection")
cn.Open conn
%>
<html>
<head>
<title>无标题文档</title>
</head>
<body>
<%
sql="select * from sell1 where online=Yes "
if request("xybhkey")<>"" then
sql=sql + "and xybh like '%"&request("xybhkey")&"%'"
end if
if request("mckey")<>"" then
sql=sql + "and mc like '%"&request("mckey")&"%'"
end if
if request("fhztkey")<>"" then
sql=sql + "and fhzt like '%"&request("fhztkey")&"%'"
end if
if request("cpmckey")<>"" then '传送过来的这个字段是不对的,因为这个字段再表sell2中。
sql=sql + "and cpmc like '%"&request("cpmckey")&"%'"
end if
sql=sql + " order by id asc"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql, cn, 1, 1
if rs.bof and rs.eof then
response.Write("没有找到您需要的记录!")
else
do while not rs.eof
%>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td><%=rs("mc")%></td>
<td><%=rs("xybh")%></td>
</tr>
<tr>
<td>产品名称</td>
<td>日期</td>
</tr>
<%
sql1="select * from sell2 where xybh like '%"&rs("xybh")&"%' "
set rs1=server.CreateObject("adodb.recordset")
rs1.open sql1,cn,1,1
if rs1.bof and rs1.eof then
response.Write("对不起,没有找到您需要的记录!")
else
do while not rs1.eof
%>
<tr>
<td><%=rs1("cpmc")%></td>
<td><%=rs1("date")%></td>
</tr>
<%
rs1.movenext
loop
end if
rs1.close
set rs1=nothing
%>
<tr>
<td><%=rs("Type")%></td>
<td><%=rs("fhzt")%></td>
</tr>
</table>
<hr>
<%
rs.movenext
loop
end if
rs.close
set rs=nothing
cn.close
set cn=nothing
%>
</body>
</html>
dim conn
conn="provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("data.mdb")
set cn=server.createobject("adodb.Connection")
cn.Open conn
%>
<html>
<head>
<title>无标题文档</title>
</head>
<body>
<%
sql="select * from sell1 where online=Yes "
if request("xybhkey")<>"" then
sql=sql + "and xybh like '%"&request("xybhkey")&"%'"
end if
if request("mckey")<>"" then
sql=sql + "and mc like '%"&request("mckey")&"%'"
end if
if request("fhztkey")<>"" then
sql=sql + "and fhzt like '%"&request("fhztkey")&"%'"
end if
if request("cpmckey")<>"" then '传送过来的这个字段是不对的,因为这个字段再表sell2中。
sql=sql + "and cpmc like '%"&request("cpmckey")&"%'"
end if
sql=sql + " order by id asc"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql, cn, 1, 1
if rs.bof and rs.eof then
response.Write("没有找到您需要的记录!")
else
do while not rs.eof
%>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td><%=rs("mc")%></td>
<td><%=rs("xybh")%></td>
</tr>
<tr>
<td>产品名称</td>
<td>日期</td>
</tr>
<%
sql1="select * from sell2 where xybh like '%"&rs("xybh")&"%' "
set rs1=server.CreateObject("adodb.recordset")
rs1.open sql1,cn,1,1
if rs1.bof and rs1.eof then
response.Write("对不起,没有找到您需要的记录!")
else
do while not rs1.eof
%>
<tr>
<td><%=rs1("cpmc")%></td>
<td><%=rs1("date")%></td>
</tr>
<%
rs1.movenext
loop
end if
rs1.close
set rs1=nothing
%>
<tr>
<td><%=rs("Type")%></td>
<td><%=rs("fhzt")%></td>
</tr>
</table>
<hr>
<%
rs.movenext
loop
end if
rs.close
set rs=nothing
cn.close
set cn=nothing
%>
</body>
</html>
我想实现的是在index.asp页面输入的关键词可以在表sell1、sell2中查询。
例如:
我在index.asp页面输入协议编号(对于字段xybh)的关键词“P01”
只有本站会员才能查看附件,请 登录
查询结果是
只有本站会员才能查看附件,请 登录
如果我在index.asp页面输入产品名称(对于的字段是表sell2中的“cpmc”)的关键词是“设备”
只有本站会员才能查看附件,请 登录
那么查询出来的结果是
只有本站会员才能查看附件,请 登录
请问大家,这个该如果实现呢,谢谢!