关于模糊查询问题

kevin82819 2014-10-16 12:08:43
一个搜索框(设置name=keyword),可以按菜谱和用料查询

菜谱表caipu caipuid cpname
1 红烧肉
2 水煮牛肉
3 烧什锦
4 咸烧白

用料表yongliao id caipuid yongliao
1 1 五花肉
2 2 肚条
3 2 鱿鱼
4 2 青笋
5 4 五花肉

请问在ASP里 该怎么实现通过搜索框既能从cpname,也能通过yongliao,查询到相应的菜谱信息,然后用料也根据对应的caipuid显示
比如,我搜索“红烧肉” 然后显示红烧肉和对应的用料,搜索“五花肉”,则显示红烧肉及咸烧白的名字和对应的用料
...全文
177 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
slwsss 2014-10-20
  • 打赏
  • 举报
回复
引用 4 楼 kevin82819 的回复:
高手们 帮帮忙呀
看下这个http://blog.csdn.net/leshami/article/details/5563199
kevin82819 2014-10-20
  • 打赏
  • 举报
回复
高手们 帮帮忙呀
suano 2014-10-20
  • 打赏
  • 举报
回复
大概是表联结的问题
三楼の郎 2014-10-20
  • 打赏
  • 举报
回复

dim strsql
strsql="select  caipuid,cpname from caipu where cpname like '%"& request("keyword") &"%'"
strsql=strsql & " union "
strsql=strsql & "select  caipuid,cpname from caipu where caipuid in (select caipuid from yongliao where yongliao  like '%"& request("keyword") &"%')"
strsql=strsql & " union "
strsql=strsql & "select caipuid,cpname from caipu where caipuid in (select caipuid from step表 where stpp_name like '%"& request("keyword") &"%')"
三楼の郎 2014-10-20
  • 打赏
  • 举报
回复

dim strsql
strsql="select  caipuid,cpname from caipu where cpname like '%"& request("keyword") &"%'"
strsql=strsql & " union "
strsql=strsql & "select  caipuid,cpname from caipu where caipuid in (select caipuid from yongliao where yongliao  like '%"& request("keyword") &"%)'"
strsql=strsql & " union "
strsql=strsql & "select caipuid,cpname from caipu where caipuid in (select caipuid from step表 where stpp_name like '%"& request("keyword") &"%)"
kevin82819 2014-10-17
  • 打赏
  • 举报
回复
还有个问题 那如果有第三个表呢 ,同样希望能把第三个step表对应的caipuid信息显示出来,谢谢··· 结构为 id caipuid stpp_name step_pic 1 1 测试 11.jpg 2 2 测试 12.jpg 3 2 测试 13.jpg 4 3 测试 14.jpg
xiao_2528276651 2014-10-17
  • 打赏
  • 举报
回复
asp模糊查询示例 //输入查询字段名称 <input name="caipuid" type="text" id="caipuid" maxlength="4"> <input name="imageField" type="image" src="images/sousuo2.gif" align="middle" width="60" height="28" border="0" onClick="return Mycheck();">//查询事件按钮 //引入连接 <%@ LANGUAGE="VBSCRIPT" CODEPAGE="936"%> <!--#include file="conn/conn.asp"--> //数据表查询 % if request.form("caipuid")<>"" then caipuid=request.form("caipuid") else caipuid=request.querystring("caipuid") end if set rs=server.CreateObject("adodb.recordset") rs1="select * from caipu where caipuid like '%"&caipuid&"%'" rs.open rs1,conn,1,1 %> //提供是否查询数据存在对话框 <%if rs.eof and rs.bof then %> <img src="images/bv.gif" width="10" height="10"> <%response.write "对不起,没有找到您要搜索的信息" response.end else if caipuid=""%> <img src="images/bv.gif" width="10" height="10"> <%response.write "对不起,没有找到您要搜索的信息!" response.end else%> //显示数据 <%=rs("caipuid")%>//显示菜单字段 <%=rs("cpname")%>//显示菜名用料字段 <%=rs("yongliao")%>//显示,,,,。字段
slwsss 2014-10-16
  • 打赏
  • 举报
回复
select top 20 cpname,yongliao from caipu left join yongliao on caipu.caipuid =yongliao.caipuid where cpname=''''&keyword''''

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧