截取输出关键字(包括并标红)前后各4个字符
表名:dhb字段:xx1 xx2 xx3 xx4 xx7 均为“文本”型
想得到结果:搜索输出关键字(包括并标红)前后各4个字符。即,前4个字符+关键字+后4个字符
<!--#include file ="conn.asp"-->
<%
key=trim(request("key"))
xx1=trim(request("xx1"))
%>
<%host=lcase(request.servervariables("HTTP_HOST"))%>
<!DOCTYPE html PUBLIC "-//W3C//Dtd html 4.01 transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=0.5,maximum-scale=2.0, user-scalable=no"/>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>my</title>
<style type="text/css">
@import url("image/Type.css");
body {
margin-top: 0px;
margin-left:-0px;
}
</style>
<style type="text/css">
a:link { text-decoration: none;color: blue}
a:active { color: blue}
a:hover { text-decoration:underline;color: red}
a:visited { text-decoration: none;color: green}
</style>
<!--表头、文字、图片-->
<table align="center" width="360" cellspacing="0" cellpadding="0" bgcolor="#228B22" bordercolor="#FFFFFF" border="0" style="border-collapse:collapse">
<td align="center" width="50" height="50"><font color="#FFFFFF" size=5><B>
<%
set rs2=conn.execute("select count(*) from dhb")
Response.write rs2(0)
rs2.close
set rs2=nothing
%> </font></td>
<td align="center" width="260" height="50"><font color="#FFFFFF" size="5"><B> 记录内容 </B></font></td>
<td align="center" width="50" height="50"> </td></td>
<table width="360" border="0" align="center" cellpadding="0" cellspacing="0" style="border-collapse:collapse;" bgcolor="#228B22">
<tr>
<td height="1"></td></tr>
<table width="360" align="center" border="0" style="border-collapse: collapse" cellpadding="0" cellspacing="0" bgcolor="#F2F2F2">
<form name="form1" action="search.asp" method="post" >
<td align="center" width="50" height="50"> </td>
<td align="center;middle" width="160">
<input type="text" name="key" value="<%=key%>" span style="width:100px;height:26px;background-color:#FFFFFF;border:#228B22 1px solid;border-radius:5px;font-size:18px;color:#FF0000;" value="输入关键字" onfocus="if(this.value=='输入关键字')this.value=''" onblur="if(this.value=='')this.value='输入关键字'" maxlength="6">
<input type="submit" name="submit" value="搜索" span style="width:50px;height:30px;background-color:#27C73F;bordercolor:#FF0000;border:0px;border-radius:8px;font-size:16px;color:#FFFFFF;">
<td align="center" width="50"><a href="index.asp"><img src="image/home.png" border="0" height="28"></a></td>
</form>
<table width="360" border="0" align="center" cellpadding="0" cellspacing="0" style="border-collapse:collapse;" bgcolor="#228B22">
<tr>
<td height="1"></td></tr>
<font color="#22BD22" size=4> <!--查询结果-->
<table width="360" align="center" cellpadding="0" cellspacing="0" border="1" bordercolor="#D1D1D1" bgcolor="F2F2F2" style="border-collapse:collapse;">
<tr height="40" align="center" font size=5>
<td width="10%"><font color="#000000" size=3> 序号 </font></td>
<td width="30%"><font color="#000000" size=3> 日期 </td>
<td width="20%"><font color="#000000" size=3> 类型 </td>
<td width="40%"><font color="#000000" size=3> 备注 </td>
</tr>
<div align="center">
<!--查询项、结果-->
<%
if key<>"" then
set conn=server.createobject("ADODB.CONNECTION")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("d b/#search.mdb")
set rst=server.createobject("adodb.recordset")
conn.open connstr
'全查询字段
'rst.open "select * from dhb where xx1 like '%%"&key&"%%' or xx2 like '%%"&key&"%%' or xx3 like '%%"&key&"%%' or xx4 like '%%"&key&"%%' or xx5 like '%%"&key&"%%' or xx6 like '%%"&key&"%%'or xx7 like '%%"&key&"%%'or xx8 like '%%"&key&"%%'or xx9 like '%%"&key&"%%'or xx10 like '%%"&key&"%%' or xx11 like '%%"&key&"%%' or xx12 like '%%"&key&"%%' order by id desc" ,conn,1,1
'只查询 xx7 字段
rst.open "select * from dhb where xx7 like '%%"&key&"%%' order by id desc" ,conn,1,1
pageNo=Request.QueryString("pageNo")
IF pageNo="" THEN pageNo=1
rst.pagesize=5
'如果没有数据记录
if rst.eof then
response.write"查询<span style='font-size:22px;color:red'><B>("&key&")</span></B> 为空"
response.end
end if
if request("page")<>"" then
epage=cint(request("page"))
if epage<1 then epage=1
if epage>rst.pagecount then epage=rst.pagecount
else
epage=1
end if
rst.absolutepage=epage
response.write "查询<span style='font-size:22px;color:red'>【"&key&"】</span> 搜到<span style='font-size:22px;color:red'>【"&rst.recordcount &"】</span>条 "
'tmpstr=rst("xx1")&rst("xx2")&rst("xx3")&rst("xx4")&" "&rst("xx5")&" "&rst("xx6")&" "&rst("xx7")&" "&rst("xx8")&" "&rst("xx9")&" "&rst("xx10")&" "&rst("xx11")&" "&rst("xx12")
tmpstr=rst("xx7")
if instr(1,tmpstr,key,1)>0 then
%>
<%
For i=1 To rst.pageSize
If rst.eof Then Exit For
%>
<tr height="40" align="center" bgcolor="#FFFFFF" onclick="location.href='modifydisplay.asp?id=<%=rst("id")%>';">
<td width="10%"><font color="#666666" size=3> <%=rst("id")%> </td>
<td width="30%"><font color="#666666" size=3> <%=rst("xx2")%> </td>
<td width="20%"><font color="#228B22" size=3><B> <%=rst("xx3")%> </td>
<td width="40%" align="left"><font color="#666666" size=2>
<!--截取备注,小于8(不含)则全部显示,多于8(含)则显示6个字符并添加...搜索关键字标红-->
<%
str=rst("xx7")
if str<>"" then
pos=instr(1,str,key)
if pos>4 then
response.Write mid(pos-4,str,8+len(key))
else
response.Write mid(1,str,pos+4+len(key))
end if
end if
%>
</td>
</tr>
<%
rst.movenext()
next
end if
%>
<tr height="40" align="center" font size=3>
<td colspan=4><font color="#000000" size=3>
<!--不显示
每页 <font color="#0000FF" size=3><B> <% =rst.pageSize %> </B></font>条
当前 <font color="#0000FF" size=3><B> <% =epage %></B></font> 页
-->
<font size=3>[
<%for i=1 to rst.pageCount %>
<a href="search.asp?page=<%=i%>&key=<%=key%>"><font color="#FF0000" size=3><B> <%=i%> </a> </B></font> <%next%>
<font size=3> ]
</td>
</table>
<%
rst.close
conn.close
end if
%>