Question : Highlight search keyword on results page.

I'm working in classic asp with SQL DB and I'm doing a very simple keyword search on my site. How would I go about highlighting the keyword on the results page. I'm assuming I could us CLASS.


MY FORM PAGE
<form name="search" method="post" action="searchresults.asp">
<table width="100%" border="1">
<tr><td><div align="center">Search our FAQ's</div></td></tr>
<tr><td>Enter Search Term</td></tr>
<tr><td><input type="text" name="searchterm">
<input type="submit" name="Submit" value="Search">
</td></tr></table></form>


MY CLASS
span.keyword {
     background: yellow;
     font-style: bold;
}


MY RESULTS PAGE
<!--#include virtual="/Connections/string.asp" -->


<%
DIM strSearchterm
strSearchterm = Request.Form("searchterm")

IF strSearchterm <> "" THEN
DIM mySQL, objRS, rsDsearch_cmd, objRS_numRows

Set rsDsearch_cmd = Server.CreateObject ("ADODB.Command")
rsDsearch_cmd.ActiveConnection = MY_STRING
mySQL = "SELECT * FROM dbo.FAQs WHERE (QUESTIONS LIKE '%" & strSearchterm & "%') OR (ANSWERS LIKE '%" & strSearchterm & "%')"
rsDsearch_cmd.CommandText = mySQL
Set objRS = rsDsearch_cmd.Execute
objRS_numRows = 0

IF objRS.EOF THEN
Response.Write "Sorry, no records were found for that searchterm"
ELSE
%>

<table width="100%">
<tr><td>Question</td><td>Answer</td></tr>
<% DO WHILE NOT objRS.EOF %>
<tr><td><%=objRS("QUESTIONS")%></td><td><%=objRS("ANSWERS")%></td></tr>
<%
objRS.MoveNext
Loop

END IF
%>
</table>

<%
ELSE
' No searchterm submitted, display blank
END IF
%>

Answer : Highlight search keyword on results page.

try replacing it . by making it case insensitive comparison  . Hope ur Queries and conxn attributes are working gud .

<%=Replace(objRS("ANSWER"),strSearchterm,"<span class=""keyword"">"&strSearchterm&"</span>",1,1,1)%>
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
<!--#include virtual="/Connections/string.asp" -->
<form name="search" method="post" action="highlight_search.asp">
<table width="100%" border="1">
<tr><td><div align="center">Search our FAQ's</div></td></tr>
<tr><td>Enter Search Term</td></tr>
<tr><td><input type="text" name="searchterm">
<input type="submit" name="Submit" value="Search">
</td></tr></table></form>
<style>
.keyword {
     background: yellow;
     font-style: bold;
}
</style>

MY RESULTS PAGE

<%
DIM strSearchterm
strSearchterm = Request.Form("searchterm")

IF strSearchterm <> "" THEN%>

<%
DIM mySQL, objRS, rsDsearch_cmd, objRS_numRows


mySQL = "SELECT * FROM dbo.FAQs WHERE (QUESTIONS LIKE '%" & strSearchterm & "%') OR (ANSWERS LIKE '%" & strSearchterm & "%')"

Set objRS = con.Execute(mySQL)
objRS_numRows = 0

IF objRS.EOF THEN
Response.Write "Sorry, no records were found for that searchterm"
ELSE
%>

<table width="100%">
<tr><td>Question</td><td>Answer</td></tr>
<% DO WHILE NOT objRS.EOF %>
<tr><td><%=Replace(objRS("ANSWER"),strSearchterm,"<span class=""keyword"">"&strSearchterm&"</span>",1,1,1)%></td>
<%
objRS.MoveNext
Loop

END IF
%>
</table>

<%
ELSE
' No searchterm submitted, display blank
END IF
%>
Random Solutions  
 
programming4us programming4us