台灣最大程式設計社群網站
線上人數
397
 
會員總數:245468
討論主題:189226
歡迎您免費加入會員
討論區列表 >> 專欄文章 >> ASP搜尋引擎:查詢關鍵字
[]  
[我要回覆]
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
ASP搜尋引擎:查詢關鍵字
價值 : 0 QP  點閱數:2002 回應數:0

樓主

站務人員 站長
門外漢
0 1580
542 9
發送站內信

捐贈 VP 給 站務人員
Search.asp
==========================================

<HTML>
<HEAD>
<% If Request("SearchText") <> "" Then
response.write "<TITLE>ASP搜尋引擎:查詢關鍵字"& Request("SearchText")& "</TITLE>"
Else
response.write "<TITLE>ASP搜尋引擎</TITLE>"
End If %>
</HEAD>
<BODY>
<FORM method="post" action="Search.asp">
<DIV align="center"></DIV>
<DIV align="center">
<TABLE bgcolor="#0033CC" border="0" bordercolorlight="#00FFFF" bordercolordark="#000000">
<TR>
<TD> <font color="#FFFFFF">查詢內容:</font> <FONT color="#CCCCCC">
<INPUT type="text" name="SearchText" size="40">
</FONT> </TD>
<TD> <FONT color="#CCCCCC">
<INPUT type="submit" name="Submit2" value="搜尋">
</FONT></TD>
</TR>
<TR>
<TD height="32"> <FONT color="#CCCCCC"> 輸出內容:<Select name="rLength" size="1" >
<OPTION value="200" SELECTED>詳細內容
<OPTION value="100">簡短內容
<OPTION value="0">簡單內容</Select>
<Select name="rResults">
<OPTION value="10" SELECTED>10
<OPTION value="25">25
<OPTION value="50">50
</Select>
</FONT> </TD>
<TD height="32"> <FONT color="#CCCCCC">
<INPUT type="reset" name="Reset" value="清除">
</FONT></TD>
</TR>
</TABLE>
</DIV>
</FORM>
<P><% If Request("SearchText") <> "" Then %> </P>
<P>查詢關鍵字 '<%=Request("SearchText")%>'<BR>
<%
Const fsoForReading = 1
Dim objFile, objFolder, objSubFolder, objTextStream
Dim bolCase, bolFileFound
Dim strDeTag, Ext, strFile, strContent, strRoot, strTag, strText, strTitle, strTitleL
Dim reqLength, reqNumber, count
strFile = ".asp .htm .html .js .txt .css"
strRoot = "/"
strText = Request("SearchText")
If Request("Case") = "on" Then bolCase = 0 Else bolCase = 1
If Request("rResults") = "10" Then reqNumber = 10
If Request("rResults") = "25" Then reqNumber = 25
If Request("rResults") = "50" Then reqNumber = 50
reqLength = Request("rLength")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strRoot))
CurURL= "http://" & Request.serverVariables("SERVER_NAME")
CurPath = objFolder
schSubFol(objFolder)
For Each objSubFolder In objFolder.SubFolders
schSubFol(objSubFolder)
Next
If Not bolFileFound Then Response.Write "找不到你要查詢的資料.."
If bolFileFound Then Response.Write "查詢結束"
Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
Sub schSubFol(objFolder)
For Each objFile In objFolder.Files
If Count + 1 > reqNumber or strText = "" Then Exit Sub
If Response.IsClientConnected Then
strext = right(objFile.Name,3)
If instr(1,strFile,strext) > 0 Then
Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading)
strContent = objTextStream.ReadAll
If InStr(1,strContent,strtext) > 0 Then
postitle = InStr(1, strContent, "<TITLE>",1)
If postitle > 0 Then
strTitle = Mid(strContent, postitle + 7, InStr(1, strContent, "</TITLE>", 1) - (postitle + 7))
Else
strTitle = "Sin Titulo"
End If
Count = Count + 1
Response.Write "<DL><DT>"& Count &" - <A HREF="&Obt_Url(objFile.path) & ">" & strTitle & "</A></DT><BR><DD>"
strTitleL = InStr(1, strContent, "</TITLE>", 1) - InStr(1, strContent, "<TITLE>", 1) + 7
strDeTag = ""
bolTagFound = False
Do While InStr(strContent, "<")
bolTagFound = True
strDeTag = strDeTag & " " & Left(strContent, InStr(strContent, "<") - 1)
strContent = MID(strContent, InStr(strContent, ">") + 1)
Loop
strDeTag = strDeTag & strContent
If Not bolTagFound Then strDeTag = strContent
If reqLength = "0" Then
Response.Write obt_url(objFile.Path) & "</DD></DL>"
Else
Response.Write Mid(strDeTag, strTitleL, reqLength) & "...<BR><FONT SIZE='2'>URL: " & obt_url(objFile.Path) & " - Ultima modificacion: " & objFile.DateLastModified & " - " & FormatNumber(objFile.Size / 1024) & "Kbytes</FONT></DD></DL>"
End If
bolFileFound = True
End If
objTextStream.Close
End If
End If
Next
End Sub
Function Obt_Url (nompath)
obt_url = CurUrl +"/"+ right(nompath,len(nompath) - len(curpath)-1)
End Function
%>
<% End If %>
</P>
</BODY></HTML>


==============================================================================
比如說有5個欄位,我可以任意選擇我想搜尋的任何欄位,然後呈現出我選擇的搜尋條件!!
================================================================================

回應者: VB Teacher vbteacher@pchome.com.tw

Dim SQLStr
SQLStr = "Select * from Table"
if Request("Field1") <> "" then
if instr(SQLStr ,"Where") > 0 then
SQLStr = SQLSTR & "And Field1 = '" & Request("Field1") & "' "
else
SQLStr = SQLSTR & "Where Field1 = '" & Request("Field1") & "' "
end if
end if
if Request("Field2") <> "" then
if instr(SQLStr ,"Where") > 0 then
SQLStr = SQLSTR & "And Field2 = '" & Request("Field2") & "' "
else
SQLStr = SQLSTR & "Where Field2 = '" & Request("Field2") & "' "
end if
end if
if Request("Field3") <> "" then
if instr(SQLStr ,"Where") > 0 then
SQLStr = SQLSTR & "And Field3 = '" & Request("Field3") & "' "
else
SQLStr = SQLSTR & "Where Field3 = '" & Request("Field3") & "' "
end if
end if
if Request("Field4") <> "" then
if instr(SQLStr ,"Where") > 0 then
SQLStr = SQLSTR & "And Field4 = '" & Request("Field4") & "' "
else
SQLStr = SQLSTR & "Where Field4 = '" & Request("Field4") & "' "
end if
end if
if Request("Field5") <> "" then
if instr(SQLStr ,"Where") > 0 then
SQLStr = SQLSTR & "And Field5 = '" & Request("Field5") & "' "
else
SQLStr = SQLSTR & "Where Field5 = '" & Request("Field5") & "' "
end if
end if

==============================================================================
回應者: pys pys33@yam.com

Function GetRequest(Field,SQL)
If Instr(SQL,"Where")<>0 Then
GetRequest=" And " & Field & "='" & Request(Field) & "'"
Else
GetRequest=" Where " & Field & " ='" & Request(Field) & "'"
End IF
End Function
Dim SQL
Dim Fields(5)
Fields(0)="Field0"
Fields(1)="Field1"
Fields(2)="Field2"
Fields(3)="Field3"
Fields(4)="Field4"
SQL="Select * From Table "
For FieldIndex=0 to 4
'---sorry for reply again--->_<
If Request(Fields(FieldIndex))<> "" Then
SQL=SQL & GetRequest(Fields(FieldIndex),SQL)
End IF
Next

本篇文章發表於2002-02-03 00:00
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
目前尚無任何回覆
   

回覆
如要回應,請先登入.