PDA

View Full Version : highlighting keyword search with different color


sahar
10-21-2005, 01:05 PM
name position location Requirement date
Amy manager Los Angeles Master in management 21/10/2005
jimmy Assistant manager Texas Degree in management 21/10/2005

as you can see above is a result for my searching using keyword. and i'm search base on keyword 'manager'.can somebody help me how to highlight the word manager in my search result with another color for example like green color above

NancyJ
10-21-2005, 01:11 PM
posting your code would help but this is a generic solution...

response.write replace(text, keyword, "<span class = 'highlight'>"&keyword&"</span>")

sahar
10-23-2005, 04:28 AM
according to your reply this is the code that i'm using in my search page.please take a look and my searching is base on (Rs("subject") and Rs.fields("rcpt")
-----------------------------------------------------------------------
-------this is a coding where to test a keyword that have enter by user----
-----------------------------------------------------------------------
<%

Dim iPageSize
Dim iPageCount
Dim iPageCurrent
Dim strOrderBy
Dim strSQL
Dim Conn
Dim Rs
Dim iRecordsShown
Dim I

iPageSize = 100

If Request.QueryString("page") = "" Then
iPageCurrent = 1
Else
iPageCurrent = CInt(Request.QueryString("page"))
End If

txtKeyWord=request.Querystring("T1")
showall = Request.QueryString("Submit0")

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open Application("ConnectionString")

Set Rs = Server.CreateObject("ADODB.Recordset")


sqlstart = "SELECT * FROM SMTPQUE where "
sqldate= "order by date "
txtKeyWord=request.Querystring("T1")

if Len(txtKeyWord) > 0 then

ArrtxtKeyWord = Split(txtKeyWord,",")

For i = 0 to Ubound(ArrtxtKeyWord)
a=0
txtKeyWordloop = ArrtxtKeyWord(i)

if sqlbody <>"" then
sqlbody = sqlbody&" or body Like '%"& txtKeyWordloop&"%' or subject Like '%"& txtKeyWordloop&"%' or rcpt like '%"& txtKeyWordloop&"%' "
else
sqlbody ="body Like '%"& txtKeyWordloop&"%' or subject Like '%"& txtKeyWordloop&"%' or rcpt like '%"& txtKeyWordloop&"%' "
end if

Next
a=a+1

sqlFinal = sqlstart & sqlbody & sqldate
'response.write ("</br>")
'response.write sqlFinal
'response.write ("</br>")

'response.end

else
sqlFinal = "select * from SMTPQUE order by date"
End if

Rs.PageSize = iPageSize

Rs.CacheSize = iPageSize

Rs.Open sqlFinal,Conn, adOpenStatic, adLockReadOnly, adCmdText

iPageCount = Rs.PageCount

If iPageCurrent > iPageCount Then iPageCurrent = iPageCount end if
If iPageCurrent < 1 Then iPageCurrent = 1 end if

'end if
%>


-----------------------------------------------------------------------
----this is coding for a table where i will show the result for searching----
------------------------------------------------------------------------

<table border="1" cellpadding="0" cellspacing="0" width="100%" id="table71" bordercolor="#E4E4E4">
<tr>
<td class="arial10" width="5%" bgcolor="#C0C0C0"><b><font size="2">S.No</font></b></td>
<td class="arial10" width="22%" bgcolor="#C0C0C0"><b><font size="2">Date</font></b></td>
<td class="arial10" width="26%" bgcolor="#C0C0C0"><b><font size="2">Rcpt</font></b></td>
<td class="arial10" width="40%" bgcolor="#C0C0C0"><b><font size="2">Subject</font></b></td>
<td class="arial10" width="6%" bgcolor="#C0C0C0"><b><font size="2">
Attach</font></b></td>
</tr>
<%
iRecordsShown = 0
i=1
Do While iRecordsShown < iPageSize And Not Rs.EOF
%>
<tr>
<%
If i mod 2 = 0 then
Response.write("<tr bgcolor=""#EEEEEE"">")
else
Response.write("<tr bgcolor=""#ffffff"">")
End if



%>
<td class="arial8" >
<p align="center"><%=i%></td>
<td class="arial8">
<%=RetrieveD(Rs.fields("date"))%></a></td>

<%
dsRcpt=Rs.fields("rcpt")
dsRcpt = Replace(dsRcpt,"<","")
dsRcpt = Replace(dsRcpt,">","")
%>
<td class="arial8" ><%=dsRcpt%></td>

<td class="arial8" ><a class="sublinks" title="View Sent Email" href='javascript:View("tsc_view_spinmail.asp?id=<%=rs.Fields("id")%>&act=view");'>
<%=Replace(Rs("subject"),"<br>",vbcrlf)%></td>
<td class="arial8">
<p align="center"><%=Rs("attachment")%></td>
</tr>

<%
iRecordsShown = iRecordsShown + 1
Rs.MoveNext
i=i+1
Loop

'end if
%>
</table>