I need the keywords highlighted and don't know how to solve this:
Code:
<%
OPTION EXPLICIT
Response.Buffer = True
Response.Expires = 0
Dim objCon
Dim rs
Dim sq
Dim sBook, sChapter, sVerse
Dim sKeyword, sKeywordb, sKeywordc, sKeywordd, sKeyworde, sKeywordf
%>
<!--#include file="adovbs.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>show an individual verse</title>
</head>
<body>
<%
' prevent sql injection attacks
If Instr(Request("b"), "'") > 0 Or Request("b") = "" Then
Response.End
ElseIf Instr(Request("c"), "'") > 0 Or Request("c") = ""Then
Response.End
ElseIf Instr(Request("v"), "'") > 0 Or Request("v") = ""Then
Response.End
End If
sBook = Request("b")
sChapter = Request("c")
sVerse = Request("v")
sKeyword = Request.QueryString("Keyword")
sKeywordb = Request("Keywordb")
sKeywordc = Request("Keywordc")
sKeywordd = Request("Keywordd")
sKeyworde = Request("Keyworde")
sKeywordf = Request("Keywordf")
Set objCon = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
If sVerse = "all" Then
sq = "select text_data, book_title, chap, vers " & _
"from bible " & _
"where book='" & sBook & "' " & _
" and chap=" & sChapter & _
" ORDER BY vers"
Else
sq = "select text_data, book_title, chap, vers " & _
"from bible " & _
"where book='" & sBook & "' " & _
" and chap=" & sChapter & _
" and vers=" & sVerse
End If
objCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("kjv.mdb") & ";" & _
"User Id=admin;Password="
rs.Open sq, objCon
%>
<b><%=rs("book_title")%> <%=rs("chap")%></b>
<p>Searching for
<%
If Trim(sKeyword & "") <> "" Then
%>
<font color="red"><b><%=sKeyword%></b></font>
<%
End If
If Trim(sKeywordb & "") <> "" Then
%>
+ <font color="blue"><b><%=sKeywordb%></b></font>
<%
End If
If Trim(sKeywordc & "") <> "" Then
%>
+ <font color="green"><b><%=sKeywordc%></b></font>
<%
End If
If Trim(sKeywordd & "") <> "" Then
%>
+ <font color="orange"><b><%=sKeywordd%></b></font>
<%
End If
If Trim(sKeyworde & "") <> "" Then
%>
+ <font color="purple"><b><%=sKeyworde%></b></font>
<%
End If
If Trim(sKeywordf & "") <> "" Then
%>
+ <font color="aqua"><b><%=sKeywordf%></b></font>
<%
End If
%>
.</p>
<%
If rs.EOF Then
Response.Write "verse not found: " & sBook & " " & sChapter & " verse " & sVerse
ElseIf IsNull(rs(0)) Then
Response.Write "verse not found: " & sBook & " " & sChapter & " verse " & sVerse
Else
Do Until rs.EOF
Response.Write "<p>" & rs("vers") & ". " & rs("text_data") &"</p>"
<!--#include file=highlight3.asp-->
rs.MoveNext
Loop
End If
rs.Close
Set rs = Nothing
objCon.Close
Set objCon = Nothing
%>
</body>
</html>
Here's the include file:
Code:
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
Function Highlight(strText, strFind, strBefore, strAfter)
Dim nPos
Dim nLen
Dim nLenAll
nLen = Len(strFind)
nLenAll = nLen + Len(strBefore) + Len(strAfter) + 1
Highlight = strText
If nLen > 0 And Len(Highlight) > 0 Then
nPos = InStr(1, Highlight, strFind, 1)
Do While nPos > 0
Highlight = Left(Highlight, nPos - 1) & _
strBefore & Mid(Highlight, nPos, nLen) & strAfter &_
Mid(Highlight, nPos + nLen)
nPos = InStr(nPos + nLenAll, Highlight, strFind, 1)
Loop
End If
End Function
</SCRIPT>
<%
'OPTION EXPLICIT
Dim strText, strFind
strFind=sKeyword
strText=rs("text_data")
strText= Highlight(strText, strFind,"<font color='red'><b>", "</b></font>")
strFind=Keywordb
strText= Highlight(strText, strFind,"<font color='blue'><b>", "</b></font>")
strFind=Keywordc
strText= Highlight(strText, strFind,"<font color='green'><b>", "</b></font>")
strFind=Keywordd
strText= Highlight(strText, strFind,"<font color='orange'><b>", "</b></font>")
strFind=Keyworde
strText= Highlight(strText, strFind,"<font color='purple'><b>", "</b></font>")
strFind=Keywordf
strText= Highlight(strText, strFind,"<font color='aqua'><b>", "</b></font>")
Response.Write strText
%>
I've only worked with the first one sKeyword with no success. I need the 6 keywords.