Her er hele scriptet:
<%
Dim ord
ord = Request.QueryString("Soegeord")
ord = Replace(ord,"'","''")
If ord = "" Then
Response.Write "Søg i databasen"
End If
If ord <> "" Then
Dim Query, rs, total, Resultat
Query = "SELECT * FROM Links WHERE "
Query = Query & "Title LIKE '%" & ord & "%' OR Description LIKE '%" & ord & "%'"
Query = Query & "ORDER BY Title"
Set rs = Connect.Execute (Query)
Function replaceSearchWord(strToReplace, strSearchWord)
Dim regEx, strRep, strRet, Match, Matches
Set regEx = new RegExp
regEx.Pattern = strSearchWord
regEx.IgnoreCase = true
regEx.Global = true
Set Matches = regEx.Execute(strToReplace)
For Each Match in Matches
strRet = Left(strToReplace, Match.FirstIndex) & "<span class=clSearchWord>"
strRet = strRet & Match.Value & "</span>"
strRet = strRet & Mid(strToReplace, Match.FirstIndex + Match.Length + 1)
Next
replaceSearchWord = strRet
End Function
'------skriver hvor mange resultater man har fået
Resultat = "Select count(*) as Found from Links WHERE Title LIKE '%" & ord & "%' OR Description LIKE '%" & ord & "%'"
Set Resultat = connect.Execute(Resultat)
total = Resultat("Found")
if rs.EOF Then
Response.Write "<p>Desværre er der ingen links der matcher dit søgeord: '<font face='fixedsys, system, courier'>" & ord & "</font>'.</p>"
Else If total = 1 Then
Response.Write "Din søgning på '<font face='fixedsys, system, courier'>" & ord & "</font>' gav kun " & total & " resultat:<br><br>"
Else
Response.Write "Din søgning på '<font face='fixedsys, system, courier'>" & ord & "</font>' gav " & total & " resultater:<br><br>"
End If
do until rs.EOF
%>
<!------------------- oplistning ---------------------------->
<b><a href="
http://<%=rs("Url")%>" target="_blank"><%=replaceSearchWord(rs("Title"), ord)%></a></b>
<br><font color="#CA7402">
<%=replaceSearchWord(rs("Description"), ord)%><%If rs("Favorit")=2 Then%><nobr><small><font color="#000099"> |favorit link|<font color="#CA7402"></small></nobr><%End If%>
<br><br>
<% rs.MoveNext %>
<% loop %>
<%End If%>
<%End If%>