⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.asp

📁 网络程序-学生个人信息管理系统。以学生个人用户实际需要为中心
💻 ASP
字号:
<%
'实现页面运行时间记录
dim startime
startime=timer()
%>
<!--#include file="../database/opendb.asp"-->
<!--#include file="../bg/css.asp"-->
<%
Function AutoKey(strKey)
CONST lngSubKey=2
Dim lngLenKey, strNew1, strNew2, i, strSubKey

'检测字符串的合法性,若不合法则转到出错页。
if InStr(strKey,"=")<>0 or InStr(strKey,"`")<>0 or InStr(strKey,"'")<>0 or InStr(strKey," ")<>0 or InStr(strKey," ")<>0 or InStr(strKey,"'")<>0 or InStr(strKey,chr(34))<>0 or InStr(strKey,"\")<>0 or InStr(strKey,",")<>0 or InStr(strKey,"<")<>0 or InStr(strKey,">")<>0 then
response.write("<font class=style1 >输入有错误,不要同时输入多个关键字(不要空格),出于安全考虑,不允许非法字符查询,谢谢~</font><a href=""#"" onclick=""history.back()"">回去再试</a>")
 response.End()

End If

lngLenKey=Len(strKey)
Select Case lngLenKey
Case 0 '若为空串,转到出错页
response.write("<font class=style1 >输入有错误,不要同时输入多个关键字(不要空格),出于安全考虑,不允许非法字符查询,谢谢~<a href=""#"" onclick=""history.back()"">回去再试</a>")
 response.End()
Case 1 '若长度为1,则不设任何值
strNew1=""
strNew2=""
Case Else '若长度大于1,则从字符串首字符开始,循环取长度为2的子字符串作为查询条件
For i=1 To lngLenKey-(lngSubKey-1)
strSubKey=Mid(strKey,i,lngSubKey)
strNew1=strNew1 & " or date like '%" & strSubKey & "%'"
strNew2=strNew2 & " or ID like '%" & strSubKey & "%'"
Next
End Select
'得到完整的SQL语句
AutoKey="Select * from data where name like '%" & strKey & "%' or content like '%" & strKey & "%'" & strNew1 & strNew2 & "order by date desc" 

End Function
%>

<%
'-----------------------------
set rst2 = Server.CreateObject("ADODB.Recordset")
    rst2.ActiveConnection=my_conn
sql="select name,content from info where english_name='colortd'" 
rst2.Open sql,my_conn,1,1 '是否打开了光标

if rst2("content")=1 then
rst2.close
sql="select name,content from info where english_name='color'" 
rst2.Open sql,my_conn,1,1 '再来查询光标色彩
tdcolor=rst2("content")
rst2.close
else
tdcolor=""
rst2.close
end if
'---------------------------
sql="select name,content from info where english_name='navipic'" 
rst2.Open sql,my_conn,1,1 '是否使用导航图片

if rst2("content") <> "0" then
navipic="<td width=""2%""><img src="&rst2("content")&"></td>"'存储图片路径
end if
rst2.close
'----------------------------
sql="select name,content from info where english_name='linedashed'" 
rst2.Open sql,my_conn,1,1 '是否虚线显示

if rst2("content")=1 then
tdline="BORDER-TOP: #ffffff  1PX DASHED;"
rst2.close
else
tdline=""
rst2.close
end if
'----------------------------
%>


<%
Dim S_Key,StrSQL
S_Key = Trim(Request("key")) '得到搜索关键字的值
If S_Key <>"" then 
    StrSQL=AutoKey(S_Key) '此处使用自定义函数 AutoKey(),该函数为实现智能搜索的核心,它实际作用是生成sql串
    rst.Open StrSQL,my_conn,1,1
    dim answer
    if rst.EOF and  rst.BOF then
      Response.Write "文章数为零~"
      rst.close
    else
        do while not rst.eof 
           answer=answer & "<table cellspacing=""0"" width=""100%"" style='BORDER-LEFT: #ffffff 1PX DASHED; BORDER-RIGHT: #ffffff  1PX DASHED;"&tdline&" '>"
            answer=answer&"<tr onmouseover=""style.backgroundColor='"&tdcolor &"';"" onmouseout=""style.backgroundColor='';"" >" & navipic & "<td width=""70%"" >" & "<a class=""style1"" href=detail.asp?id="&rst("ID")& ">" & rst("name")& "</a></td><td align=""right"" class=""style1"">" & rst("date")& "</td></tr>"
           answer=answer & "</table>"
           rst.movenext
       loop 
       rst.close
    end if
End If
%>
<%response.write( answer )%>
<!--#include file="../database/closedb.asp"-->
<%
dim endtime
endtime=timer()
%>
<br><span class="style1">页面执行时间:<%=FormatNumber((endtime-startime)*1000,3)%>毫秒</span>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -