If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > I have another highlighting problem.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-13-05, 02:28
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 494
I have another highlighting problem.

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")%>&nbsp;&nbsp;<%=rs("chap")%></b>
<p>Searching for
<%
If Trim(sKeyword & "") <> "" Then
%>
         <font color="red"><b><%=sKeyword%></b></font>
<%
End If
If Trim(sKeywordb & "") <> "" Then
%>
          &nbsp;+&nbsp;<font color="blue"><b><%=sKeywordb%></b></font>
<%
End If
If Trim(sKeywordc & "") <> "" Then
%>
          &nbsp;+&nbsp;<font color="green"><b><%=sKeywordc%></b></font>
<%
End If
If Trim(sKeywordd & "") <> "" Then
%>
          &nbsp;+&nbsp;<font color="orange"><b><%=sKeywordd%></b></font>
<%
End If
If Trim(sKeyworde & "") <> "" Then
%>
          &nbsp;+&nbsp;<font color="purple"><b><%=sKeyworde%></b></font>
<%
End If
If Trim(sKeywordf & "") <> "" Then
%>
          &nbsp;+&nbsp;<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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On