?
Solved

How to highlight the search keyword from the search result?

Posted on 2012-08-21
10
Medium Priority
?
1,255 Views
Last Modified: 2012-08-22
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!
0
Comment
Question by:Stiebel Eltron
  • 7
  • 3
10 Comments
 

Author Comment

by:Stiebel Eltron
ID: 38315154
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>
0
 
LVL 9

Accepted Solution

by:
teebon earned 2000 total points
ID: 38315211
Hi Stiebel,

use vbscript replace function:

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

Open in new window

0
 

Author Comment

by:Stiebel Eltron
ID: 38315218
Hi there teebon!

Thank you for your response, but to which line do we need to put that REPLACE line?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Stiebel Eltron
ID: 38315227
Got it! Sorry...
0
 

Author Closing Comment

by:Stiebel Eltron
ID: 38315229
Excellent!
0
 

Author Comment

by:Stiebel Eltron
ID: 38315559
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>") %>
0
 

Author Comment

by:Stiebel Eltron
ID: 38315562
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...
0
 
LVL 9

Expert Comment

by:teebon
ID: 38315566
Has the code been modified again?
Are you testing on the same server?
0
 
LVL 9

Expert Comment

by:teebon
ID: 38315572
Hi stiebel,

try to add one more parameter as below:

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

Open in new window

0
 

Author Comment

by:Stiebel Eltron
ID: 38319548
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...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month17 days, 2 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question