日期:2014-05-17  浏览次数:20802 次

新手求教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" ce