我的一个搜索的代码!欢迎指出不足!希望能改进! 不指定

Else , 2006/06/05 01:49 , 代码片段,演示也有 , Comments(0) , Reads(3080) , Via Original
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="conn.asp"-->
<%
on error resume next
%>

</head>

<body>
<script language="JavaScript" type="text/javascript" src="js/imgResize.js"></script>
<!--#include file="head.asp" -->
<table width="782" border="0" align="center" cellpadding="0" cellspacing="0">
 <tr valign="top">
   <td width="213" background="images/index_25.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
         <tr>
           <td><img src="images/index_26.gif" width="213" height="30" alt="" /></td>
         </tr>
         <tr>
           <td valign="top" background="images/index_31.gif"><table width="175"  border="0" align="center" cellpadding="0" cellspacing="0">
               <%exec="select * from procat order by value asc"
     set rs=server.createobject("adodb.recordset")
     rs.open exec,conn,1,1
     if rs.eof then
     %>
               <tr>
                 <td width="18"></td>
                 <td width="157" height="24">未加类别</td>
               </tr>
               <%else
       while not rs.eof
     %>
               <tr>
                 <td width="18"></td>
                 <td width="157" height="24"><a href="products.asp?id=<%= rs("id") %>"><%= rs("catname") %></a></td>
               </tr>
               <%rs.movenext
       wend
       rs.close
       set rs=Nothing
       end if
       %>
           </table></td>
         </tr>
         <tr>
           <td><img src="images/index_35.gif" alt="" width="213" height="23" border="0" usemap="#Map5" /></td>
         </tr>
         <tr>
           <td><img src="images/index_36.gif" width="213" height="7" alt="" /></td>
         </tr>
       </table>
   </td>
   <td width="569" background="images/bg_right.gif"><table width="569" height="209" border="0" cellpadding="0" cellspacing="0">
     <tr>
       <td height="31" colspan="3"><img src="images/search.gif" alt="" width="569" height="31" border="0" /></td>
     </tr>
     <tr>
       <td height="11" colspan="3"><img src="images/index_20.gif" width="569" height="11" alt="" /></td>
     </tr>
     <tr>
       <td width="30" height="158" valign="bottom" background="images/tableleftbg.gif"><img src="images/index_21.gif" width="30" height="158" alt="" /></td>
       <td width="521" height="158" valign="top">
      <%
     dim search
     search=trim(request.querystring("search"))
     if search="" then        
     %>
   
   
   
   <form id="form1" name="form1" method="get" action="search.asp">
         <table width="429" border="0" align="center" cellpadding="5" cellspacing="0">
           <tr>
             <td colspan="2" align="center"><a href="http://www.rcsm.cn" target="_blank"><img src="images/logo1.gif" width="169" height="58" border="0" /></a></td>
           </tr>
           <tr>
             <td align="center"><label>关 键 字 →</label></td>
             <td><input name="search" type="text" id="search" size="30" maxlength="20" /></td>
           </tr>
           <tr>
             <td align="center"><label>请 选 择 →</label></td>
             <td><label>
               <input name="cho" type="radio" value="name" checked="checked" />
             </label>
名称
<label>
<input name="cho" type="radio" value="type" />
</label>
型号
<label>
<input type="radio" name="cho" value="two" />
名称+类别
</label></td>
           </tr>
           <tr>
             <td align="center">产 品 类 别
               <label></label></td>
             <td><select name="class" class="select" id="class">
               <option value="all" selected="selected">全部产品</option>
               <%exec="select * from procat order by value asc"
         set rs=server.createobject("adodb.recordset")
         rs.open exec,conn,1,1
         if rs.eof then
         %>
               <option value="">没有分类</option>
               <%else
           do while not rs.eof
         %>
               <option value="<%=rs("id")%>"><%=rs("catname")%></option>
               <%rs.movenext
           loop
         end if
         rs.close
         set rs=Nothing%>
             </select>
               <input name="Submit" type="submit" class="mymenu" value="搜索" /></td>
           </tr>
         </table>
       </form>
 
 
 <%else
 dim cho,mytype,asearch
 asearch=request.querystring("search")
 cho=request.querystring("cho")
 mytype=request.querystring("class")
 
 if cho="name" then
   strcho="name like'%"&search&"%' "
 elseif cho="type" then
   strcho="url like'%"&search&"%' "
 elseif cho="two" then
   strcho="name like'%"&search&"%' or url like'%"&search&"%' "
 else
   strcho="name like'%"&search&"%' "
 end if
 
 
 if mytype="all" then
    typestr="not(piccatid=0)"
 else
   typestr="piccatid="&mytype&" "
 end if
 
  exec="select * from list where "&strcho&" and "&typestr&" order by id desc"
          set rs=server.createobject("adodb.recordset")
          rs.open exec,conn,1,1
          if rs.eof then
              response.write"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;没有找到"&asearch
          else
          rs.PageSize=10
         pagecount=rs.PageCount
         page=int(request.QueryString ("page"))
         if page<=0 then page=1
         if page>rs.pagecount then page=rs.pagecount    
          if request.QueryString("page")="" then page=1
          rs.AbsolutePage=page
          rssum=rs.recordcount    
 for i=1 to rs.PageSize
 %>      
<table width="100%" height="30" border="0" cellpadding="5" cellspacing="0" class="underline">
 <tr>
   <td width="9%">名称:</td>
   <td width="51%"><a href="show.asp?id=<%=rs("id")%>"><%=red(rs("name"),asearch)%></a></td>
   <td width="9%">型号:</td>
   <td width="31%"><%=red(rs("url"),asearch)%></td>
 </tr>
 <tr>
   <td colspan="4"><a href="show.asp?id=<%=rs("id")%>"><%= red(leftString(stripHTML(rs("content")),300),asearch)%>……</a></td>
   </tr>
 <tr>
   <td colspan="4"><a href="<%=SiteUrl%>/show.asp?id=<%=rs("id")%>">网址:<%=SiteUrl%>/show.asp?id=<%=rs("id")%></a></td>
   </tr>
</table>    
<%
rs.movenext
if rs.eof then exit for
next
%>  
<div align="center">

   <%if search="" then
       link="<a href=?page="
       else
       link="<a href=?search="&asearch&"&cho="&cho&"&class="&request.querystring("class")&"&page="
       end if%>
       总共有<font color=red><%=rssum%></font>条记录||共有<font color=red><%=pagecount%></font>页,
       当前是<font color=red><%=page%></font>页||
       <%if rssum<rs.pagesize then%>
         <%response.write"下一页||上一页||首页||末页"%>
       <%elseif page=1 and rssum>rs.pagesize then%>
         <%=link%><%=page+1%>><font color=#6633CC>下一页</font></a>||
         上一页||首页||<%=link%><%=pagecount%>><font color=#9999ff>末页</font></a>
       <%elseif page=pagecount and rssum>rs.pagesize then%>
         下一页||<%=link%><%=page-1%>><font color=#3333cc>上一页</font></a>||
         <%=link%>1><font color=#cc99ff>首页</font></a>||末页
       <%else%>
         <%=link%><%=page+1%>>下一页</a> ||<%=link%><%=page-1%>>上一页</a>||
         <%=link%>1>首页</a>||<%=link%><%=pagecount%>>末页</a>
       <%End if'分页部分%>  
</div>
 <%end if%>


<%end if%>

</td>
       <td width="18" background="images/tablebg.gif"></td>
     </tr>
     <tr>
       <td height="9" colspan="3"><img src="images/index_28.gif" width="569" height="9" alt="" /></td>
     </tr>
   </table>
   </td>
 </tr>
</table>
<map name="Map5" id="Map5">
 <area shape="rect" coords="156,3,198,17" href="products.asp" />
</map>
<!--#include file="copyright.asp" -->
<%

''''用正则表达式过滤html代码
Function stripHTML(strHTML)
'Strips the HTML tags from strHTML

Dim objRegExp, strOutput
Set objRegExp = New Regexp

objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<.+?>"

'Replace all HTML tag matches with the empty string
strOutput = objRegExp.Replace(strHTML, "")

'Replace all < and > with < and >
strOutput = Replace(strOutput, "<", "<")
strOutput = Replace(strOutput, ">", ">")

stripHTML = strOutput 'Return the value of strOutput

Set objRegExp = Nothing
End Function

Function red(str1,str2)
 if str1<>"" and str2<>"" then
 
 str1=replace(str1,str2,"<span class=red>"&str2&"</span>")
   red=str1
else
 exit Function
end if
End Function
conn.close
set conn=Nothing%>
</body>
</html>
Tags: ,
Add a comment

Nickname

Site URI

Email

Enable HTML Enable UBB Enable Emots Hidden Remember [Login] [Register]