Link to home
Start Free TrialLog in
Avatar of Stiebel Eltron
Stiebel EltronFlag for Thailand

asked on

How to highlight the search keyword from the search result?

Dear EE experts,

We would like to ask for tech support on how to highlight the Search Keyword from the search results. How to BOLD it?
For example, if user search: AQ , and from the results there are AQ Series, Aqua Series, Aquatic Image, we would like the keyword "AQ" or "Aq" be bold.

Thank you!
Avatar of Stiebel Eltron
Stiebel Eltron
Flag of Thailand image

ASKER

Sorry, here's the script:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim myConnection, rsProducts
Dim connectString
Dim sqlContent
Dim requestSeries

connectString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=SERVER; PORT=PORT; DATABASE=DB; USER=UN; PASSWORD=PW; OPTION=0;"

Set myConnection = Server.CreateObject("ADODB.Connection")
Set rsProducts = Server.CreateObject("ADODB.Recordset")

'SeriesID = Request.QueryString("SeriesID")
myConnection.Open connectString

requestSeries = Request.Form("Series")

      sqlContent = "Select * From series WHERE series_name LIKE '%" & requestSeries &"%'"
      
      Set rsProducts = myConnection.Execute(sqlContent)
      
      If (rsProducts.BOF) AND (rsProducts.EOF) then
            Response.Write("Sorry, but Product Series " & requestSeries & " was not found.")
            
      Else      
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />

<meta name="GENERATOR" content="Mozilla/4.7 [en] (Win98; I) [Netscape]" />


<title>..:: Stiebel Eltron's iPhoto Stock Gallery - Powered by STE IT Dept. ::..</title>


</head>

<body bgproperties="fixed" bgcolor="#000000" onload="javascript:startmenu()">
<table width="760" border="0" cellspacing="3" cellpadding="1">
  <tr>
    <td><img src="IMG/logo_res.jpg" alt="STIEBEL ELTRON" /></td>
    <td valign="top" bgcolor="#666666">
          <SCRIPT LANGUAGE="JavaScript">
          <!-- Begin
            showImage();
            //  End -->
            </script>
    </td>
    <td><img src="IMG/white_square.png" alt="STIEBEL ELTRON" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="right" bgcolor="#999999"><font face="Verdana, Geneva, sans-serif" color="#FFFFFF">
    <%
   '// If user is logged in show name and logout link
   If Session("loggedin") = true Then
      Response.Write "Welcome: " & Session("FName")
      Response.Write "<br /><a href=""login/logout.asp"">Logout</a>"
   Else
      Response.Write "<a href=""ste-iphoto-login2.asp"" title=""CLICK TO LOGIN"">REGISTERED USERS</a>"
   End If
      %>&nbsp;
      </td>
    <td bgcolor="#666666" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
   
    <td align="left" bordercolor="#999999" bgcolor="#FFFFFF">
          Search request result from the keyword: <b><% Response.Write("" & requestSeries & "") %></b>
      </td>
      <td bgcolor="#999999" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
   
      <td align="left" bordercolor="#999999" bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="3" cellpadding="1">
      <tr>
          <td bgcolor="#999999" align="center">
        ID
        </td>
          <td bgcolor="#999999" align="center">
        SERIES NAME
        </td>
          <td bgcolor="#999999" align="center">
        LINK
        </td>
      </tr>
   
    <!-- Get Data -->
    <% do while not rsProducts.EOF %>
   
    <tr>
          <td align="center" class="td2" bgcolor="#CCCCCC">
              <%=rsProducts("categoryid")%>
        </td>
          <td class="td2" bgcolor="#CCCCCC">
              <%=rsProducts("series_name")%>
        </td>
          <td class="td2" bgcolor="#CCCCCC">
              <%
                  if rsProducts("categoryid") = 2 then
                  %>
            <a href="http://www.cssasia.info/ste/ste-search-result.asp?SeriesID=<%=rsProducts("seriesid")%>">Shower Unit</a>
            <%
                  
                  end if
                  %>
        </td>
    </tr>
    <% rsProducts.MoveNext %>
    <% loop %><!--Next Row-->

</table>
ASKER CERTIFIED SOLUTION
Avatar of teebon
teebon
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi there teebon!

Thank you for your response, but to which line do we need to put that REPLACE line?
Got it! Sorry...
Excellent!
Hello to you again teebon!

Just want to ask, why does it stops to highlight the search keyword?
earlier it's working just fine, but after few hours of testing, we noticed that the highlight of every keyword isn't working again...
we're still using this line: <%=Replace(rsProducts("series_name"),requestSeries,"<b>" & requestSeries & "</b>") %>
ah ok, we found the problem, the keyword should be SAME with the search result. The uppercase and lower case of each letter should be the same, otherwise it won't highlight at all...
Has the code been modified again?
Are you testing on the same server?
Hi stiebel,

try to add one more parameter as below:

<%=Replace(rsProducts("series_name"),requestSeries,"<b>" & requestSeries & "</b>",,,1) %>

Open in new window

hi teebon! thanks for your reply.
We didn't modify the codes.
We follow what you advised, replace the previous script with the new one, but with the latest, we received error result.

"An error occurred on the server when processing the URL. Please contact the system administrator.
If you are the system administrator please click here to find out more about this error."

So we go back with this line of script: <%=Replace(rsProducts("series_name"),requestSeries,"<b>" & requestSeries & "</b>") %>

that you advised earlier...