| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 393 人关注过本帖
标题:多关联表查询问题,请大家进来帮个忙,不甚感激!
只看楼主 加入收藏
QQ273080973
Rank: 2
等 级:论坛游民
帖 子:14
专家分:39
注 册:2011-7-7
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
多关联表查询问题,请大家进来帮个忙,不甚感激!
我的源代码:[local]1[/local]

数据库lunatic.mdb中的2个关联表有一个相同的字段“Number”,如下:
BigClass:  [local]2[/local]
SmallClass:[local]3[/local]

提交关键字页面index.asp的代码:
程序代码:
<html>
<head>
<title>.............</title>
</head>
<body>
<form action="search.asp" method="post" name="search" target="_blank">
  <p>表BigClass的Big_Title字段
    <input name="Big_Title" type="text" value="" size="20"> </p>
  <p>表SmallClass的Small_Title字段
    <input name="Small_Title" type="text" value="" size="20"></p>
  <p><input type="submit" name="Submit" value="搜索"></p>
</FORM>
</body>
</html>


查询结果页面search.asp的代码:
程序代码:
<%
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.mappath("database/lunatic.mdb")+";Persist Security Info=False"
set conn = Server.CreateObject("ADODB.Connection")
conn.open strConn
%>
<html xmlns="http://www.>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<%
  sql="select * from BigClass where Big_Title like '%"&request("Big_Title")&"%'  "
  set rs=Server.CreateObject("ADODB.RecordSet")
  rs.open sql,conn,1,1

 
  if rs.bof and rs.eof then
  response.Write("对不起,没有找到您需要的记录!")
  else
  do while not rs.eof
  %>
<table align="center" width="400" border="0" cellpadding="3" cellspacing="0">
  <tr style="color:#FF0000">
    <td width="200"><%=rs("Number")%></td>
    <td width="200"><%=rs("Big_Title")%></td>
  </tr>
  <%
  sqlt="select * from SmallClass where Number = '"&rs("Number")&"' and Small_Title like '%"&request("Small_Title")&"%' "
  set rst=Server.CreateObject("ADODB.RecordSet")
  rst.open sqlt,conn,1,1

 
  if rst.bof and rst.eof then
  response.Write("<tr><td style='font-size:13px; color:#FF0000'>小类下没有记录!</td></tr>")
  response.Write("<tr><td>&nbsp;</td></tr>")
  else
  do while not rst.eof
  %>
  <tr>
    <td><%=rst("Small_Title")%></td>
    <td><%=rst("Small_Name")%></td>
  </tr>
  <%
  rst.movenext
  loop
  end if
  rst.close
  Set rst = Nothing
  %>
</table>
<hr>
<%
  rs.movenext
  loop
  end if
  rs.close
  Set rs = Nothing
  conn.close
  set conn=nothing
  %>
</body>
</html>


我在index.asp页面提交一个关键字“手持终端”进行查询:
[local]4[/local]

查询出来的结果:
[local]5[/local]

请问大家,我如何让“XS004   福建移动公司”这条记录不显示出来,只读取前面的XS001、XS002、XS003这3条记录的“手持终端”的信息。也就是读取的结果如下图:
[local]6[/local]

请问大家怎么实现,谢谢!
搜索更多相关主题的帖子: 关键字 源代码 action color 
2011-07-07 19:45
QQ273080973
Rank: 2
等 级:论坛游民
帖 子:14
专家分:39
注 册:2011-7-7
收藏
得分:0 
好像图没有上传成功,我再贴一次,大家看看我的想法能否实现哈。

我的源代码:
Search.rar (11.63 KB)


读取页面代码:
程序代码:
<%
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.mappath("database/lunatic.mdb")+";Persist Security Info=False"
set conn = Server.CreateObject("ADODB.Connection")
conn.open strConn
%>
<html xmlns="http://www.>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<%
  sql="select * from BigClass where Big_Title like '%"&request("Big_Title")&"%'  "
  set rs=Server.CreateObject("ADODB.RecordSet")
  rs.open sql,conn,1,1

 
  if rs.bof and rs.eof then
  response.Write("对不起,没有找到您需要的记录!")
  else
  do while not rs.eof
  %>
<table align="center" width="400" border="0" cellpadding="3" cellspacing="0">
  <tr style="color:#FF0000">
    <td width="200"><%=rs("Number")%></td>
    <td width="200"><%=rs("Big_Title")%></td>
  </tr>
  <%
  sqlt="select * from SmallClass where Number = '"&rs("Number")&"' and Small_Title like '%"&request("Small_Title")&"%' "
  set rst=Server.CreateObject("ADODB.RecordSet")
  rst.open sqlt,conn,1,1

 
  if rst.bof and rst.eof then
  response.Write("<tr><td  colspan='2' style='font-size:13px;'>对不起,该大类下的小类没有记录!</td></tr>")
  else
  do while not rst.eof
  %>
  <tr>
    <td><%=rst("Small_Title")%></td>
    <td><%=rst("Small_Name")%></td>
  </tr>
  <%
  rst.movenext
  loop
  end if
  rst.close
  Set rst = Nothing
  %>
</table>
<hr>
<%
  rs.movenext
  loop
  end if
  response.Write("总共记录数:"&rs.RecordCount&"")
  rs.close
  Set rs = Nothing
  conn.close
  set conn=nothing
%>
</body>
</html>


全部读取的话就是下面的4条记录:
图片附件: 游客没有浏览图片的权限,请 登录注册


如果按照“配件”来查询的话,结果就是:
图片附件: 游客没有浏览图片的权限,请 登录注册


我想实现的效果是:
图片附件: 游客没有浏览图片的权限,请 登录注册


就是说如果大类下面的小类没有记录,那么这条大类也不显示出来,不知道能不能实现。
2011-07-08 14:43
kombel
Rank: 2
等 级:论坛游民
帖 子:69
专家分:48
注 册:2011-6-15
收藏
得分:20 
嗯 我学到了
2011-07-11 14:30
快速回复:多关联表查询问题,请大家进来帮个忙,不甚感激!
数据加载中...
 
   



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

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