Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlight matching results in bold

Status
Not open for further replies.

tayorolls

MIS
May 8, 2007
42
US
Hi,

I have a search feature which searches for the URL from a database. I am able to get all the results from the database with the closest matches. However is there a way I can highlight the words in bold so that in a list of URLs return, it shows the URLs and the matched word.

Code:
SELECT     URL
FROM         Link
WHERE     (URL LIKE '%FDA%')
ORDER BY URL DESC

Display of results:

Code:
If Not rsResults.EOF Then
        Do while not rsResults.EOF
        %>
            Response.Write rsResults("URL") & "<br />"
        <%
        rsResults.MoveNext
        Loop
	Else
	%>
	    <div class="section_message">
	        <ul><li class="message_info"><b>There are no records!</b></li></ul>
	    </div>
	<%	    
	End If
 
In the example above:[tt]
Response.Write Replace(rsResults("URL"),"FDA","<b>FDA</b>") & "<br />"[/tt]
 
Thanks for the response. But I do not see any results. This is what I changed it to:

Code:
sSearch = Request.Form("Search")

Display the results

Code:
'Build SQL statements based on the Search Criteria.

If sSearch <> "" Then
    sSQL = "SELECT LinkTitle, URL FROM Link " & _
           "WHERE LinkTitle LIKE '%" & sSearch & "%' " &_
           "ORDER BY LinkTitle DESC"
    'Response.Write "sSQL: " & sSQL & "<br>" 
    'Response.End
End If

Set rsResults = Server.CreateObject("ADODB.RecordSet")

rsResults.Open sSQL, Conn

    If Not rsResults.EOF Then
        sSearchBold = "<span class=""highlight"">" & sSearch & "</span>"
        Do while not rsResults.EOF        
            %>
            <br />            
            <a href="<%=rsResults("URL") %>"><% =Replace(rsResults("LinkTitle"),sSearch, sSearchBold)%></a><br />
            <%
        rsResults.MoveNext
        Loop
	Else
	%>
	    <br />
	    <div class="section_message">
	        <ul><li class="message_info"><b>There are no records!</b></li></ul>
	    </div>
	<%	    
	End If
rsResults.Close
%>

I do not get any errors and at same time I do not get any highlight as well.

CSS code:

Code:
.highlight { background-color: yellow; }
 
It was not displaying because of case-sensitivity.

If I type anti in the searchbox, then it would not highlight any of the following:

Code:
Recent Medical Device Antitrust Cases

Hogan and Hartson Health Care Antitrust Update

Hillenbrand Settles Antitrust Lawsuit for $300 M

Focus on Antitrust

Anti-kickback Law

However if I type "Anti", then it would highlight "Anti" in a yellow background.

I need to find a way to ignore a the case and highlight the matches irrespective of the case.

Thanks for the response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top