新手求教asp关键字模糊查询的问题搜索页面和显示页面在同一个页面,都为memeber2.asp代码如下:HTML codedi
新手求教asp关键字模糊查询的问题
搜索页面和显示页面在同一个页面,都为memeber2.asp
代码如下:
- HTML code
<div class="top33"> <!--#include file="left.asp" --> <div class="right3"> <div class="right_top"> <div style="float:left; height:24px; line-height:24px;">您所在的位置:<a href="index.asp">首页</a> >> <a href="member.asp">会员中心</a></div> <form name="frm_Search" method="post" action="member2.asp"> <div style="float:left; margin-left:10px;"> 酒店名称:<input type="text" name="key" size="12" /> 所属地区:<select name="category"> <option value="123"> —请选择—</option> <option value="1">潍城区</option> <option value="2">奎文区</option> <option value="3">高新区</option> <option value="4">坊子区</option> <option value="5">寒亭区</option> </select> <input type="submit" value="查询"> </div> </form> </div> <div class="right_bottom"> <div class="right2_01"><img src="images/hyzx.jpg" /></div> <div class="right3_02"> <% key=request("key") '获取搜索的关键字 category=request("category") '获取搜索的类别 sql="select * from allpic where 1=1 " if category<>"" then sql=sql&" and "&category&" like '%" & key & "%'" end if set rs=server.createobject("adodb.recordset") rs.open sql,conn,1,1 if rs.eof then response.write"<tr><td colspan=7 height=25 bgcolor=#FFFFFF align=center onMouseOver=this.style.background='#E1F4EE'; onMouseOut=this.style.background='#ffffff'>暂时没有产品,敬请期待.</td></tr>" else rs.Pagesize=12 page=clng(request("page")) if page<1 or page=empty then page=1 if page>rs.pagecount then page=rs.pagecount rs.Absolutepage=page i=1 do while not rs.eof%> <div class="ShowBlock"> <a href="eachmember.asp?id=<%=rs("id")%>" class="PicArea"><img src="admin/<%=rs("pic")%>" width="137px" height="168px" title="<%=rs("title")%>" alt="<%=rs("title")%>" border="0" /></a> <div style="height:48px; line-height:24px; vertical-align:middle; text-align:center;"><%=rs("title")%></br><%=rs("tel")%></div> </div> <% i=i+1 if i>12 then exit do rs.movenext loop end if %> <div style="padding:2px; width:95%; margin:auto; margin-top:30px; margin-bottom:10px; float:left;"> <form action=<%=myself%> method=get style="padding:0; margin:0;"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="50%" valign="top"><div align="right"> <table width="265" height="20" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="22" valign="middle"><div align="right"><a href=<%=myself%>?page=1><img src="images/ym_04.jpg" border="0" style="margin-right:5px;"/></a></div></td> <td height="22" valign="middle"><div align="right"><a href=<%=myself%>?page=<%=(page-1)%>><img src="images/ym_06.jpg" border="0" style="margin-right:5px;"/></a></div> </td> <td height="22" valign="middle"><div align="right"><a href=<%=myself%>?page=<%=(page+1)%>><img src="images/ym_07.jpg" border="0" style="margin-right:5px;"/></a></div> </td> <td height="22" valign="middle"><div align="right"><a href=<%=myself%>?page=<%=rs.pagecount%>><img src="images/ym_09.jpg" border="0" style="margin-right:5px;" /></a> </div></td> <td height="22" valign="middle"><div align="right">第1页/共3页</div></td> </tr> </table> </div></td> </tr> </table> </form> </div> </div> </div> </div> </div>
数据库字段:id ,title, category,pic,newscontent, tel,...等。 需要实现的功能是输入title的模糊字段并且通过下拉列表选择所属地区即可显示出该产品信息。
我写的代码不知道哪里有错,不管是输入模糊字段还是选择下拉列表都查询不到产品信息。请各位大虾指教一二。小妹初学asp,请不吝赐教呀。多谢了^_^
[解决办法]
- HTML code
<div class="top33"> <!--#include file="left.asp" --> <div class="right3"> <div class="right_top"> <div style="float:left; height:24px; line-height:24px;">您所在的位置:<a href="index.asp">首页</a> >> <a href="member.asp">会员中心</a></div> <form name="frm_Search" method="post" action="member1.asp"> <div style="float:left; margin-left:10px;"> 酒店名称:<input type="text" name="key" size="12"/> 所属地区:<select name="category"> <option value="请选择"> —请选择—</option> <% set rs1=server.createobject("adodb.recordset") sql1="select * from picfl order by id desc" rs1.open sql1,conn,3,3 if rs1.eof then response.Write "null" else do while not rs1.eof %> <option value="<%=rs1("category")%>" ><%=rs1("category")%></option> <% rs1.movenext loop end if rs1.close set rs1=nothing %> </select> <input name="Query" type="submit" value="查询"> </div> </form> </div> <div class="right_bottom"> <div class="right2_01"><img src="images/hyzx.jpg" /></div> <div class="right3_02"> <% myself=request.servervariables("path_info") key=trim(request("key")) '获取搜索的关键字 category=trim(request("category")) '获取搜索的类别] if len(key)=0 and category="请选择" then response.Write "<script>alert('请输入酒店名称或选择酒店地区才可以查询');history.go(-1);</script>" else set rs=server.createobject("adodb.recordset") if len(key)<>0 then if category="请选择" then sql="select * from allpic where title like '%"&key&"%'" else sql="select * from allpic where title like '%"&key&"%' and category='"&category&"'" end if else sql="select * from allpic where category='"&category&"'" end if 'response.Write sql 'response.End() rs.open sql,conn,3,1 if rs.eof then response.Write "<script>alert('暂时没有找到您查询的记录');history.go(-1);</script>" end if rs.Pagesize=12 page=clng(request("page")) if page<1 or page=empty then page=1 if page>rs.pagecount then page=rs.pagecount rs.Absolutepage=page i=1 do while not rs.eof %> <div class="ShowBlock"> <a href="eachmember.asp?id=<%=rs("id")%>" class="PicArea"><img src="admin/<%=rs("pic")%>" width="137px" height="168px" title="<%=rs("title")%>" alt="<%=rs("title")%>" border="0" /></a> <div style="height:48px; line-height:24px; vertical-align:middle; text-align:center;"><%=rs("title")%></br><%=rs("tel")%></div> </div> <% i=i+1 if i>12 then exit do rs.movenext loop end if %> <div style="padding:2px; width:95%; margin:auto; margin-top:30px; margin-bottom:10px; float:left;"> <form action=<%=myself%> method=get style="padding:0; margin:0;"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="50%" valign="top"><div align="right"> <table width="265" height="20" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="22" valign="middle"><div align="right"><a href=<%=myself%>?page=1&key=<%=key%>&category=<%=category%>><img src="images/ym_04.jpg" border="0" style="margin-right:5px;"/></a></div></td> <td height="22" valign="middle"><div align="right"><a href=<%=myself%>?page=<%=(page-1)%>&key=<%=key%>&category=<%=category%>><img src="images/ym_06.jpg" border="0" style="margin-right:5px;"/></a></div> </td> <td height="22" valign="middle"><div align="right"><a href=<%=myself%>?page=<%=(page+1)%>&key=<%=key%>&category=<%=category%>><img src="images/ym_07.jpg" border="0" style="margin-right:5px;"/></a></div> </td> <td height="22" valign="middle"><div align="right"><a href=<%=myself%>?page=<%=rs.pagecount%>&key=<%=key%>&category=<%=category%>><img src="images/ym_09.jpg" border="0" style="margin-right:5px;" /></a> </div></td> <td height="22" valign="middle"><div align="right">第<%=page%>页/共<%=rs.pagecount%>页</div></td> </tr> </table> </div></td> </tr> </table> </form> </div> </div> </div> </div> </div>
