Print Page | Close Window

Count the number of times the search term

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: General Discussion
Forum Description: General discussion and chat on any topic.
URL: https://forums.webwiz.net/forum_posts.asp?TID=3395
Printed Date: 29 March 2026 at 3:41pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Count the number of times the search term
Posted By: woodleyw
Subject: Count the number of times the search term
Date Posted: 08 June 2003 at 10:22pm
Here are the facts:

1). I built a site search engine and it is connected to a SQL database

My problem is that I would like to be able to count and display the number of times the search term appears in the results page.  I am seeking a script or function that would recognize the search term and then count the number of times it appears for each instance.

I am able to bold the search term everytime it appears in the results page but I can't figure out the code to establish the count.  I want the count to stop at "5".  I know that I must Dim variables and then assign the variable to the search term and then increment the count for everytime the search term appears but I just can't get the code to work.

Any assistance in solving this would be appreciated.

wlw

-------------
woodleyw



Replies:
Posted By: farrukh
Date Posted: 09 June 2003 at 5:13am

Page = Request.QueryString("pg")
 If Page="" then
  Page = 1
Else
  Page = CInt(Page)
End if

Set conn = server.CreateObject("ADODB.Connection")
Set rs = server.CreateObject("ADODB.RecordSet")

conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("urdatabase.mdb")
conn.CursorLocation = 3 

if rs.recordcount = 0 then
 response.write "Record Doesn't Found"
else

 Rs.PageSize = 8            'Indicates Records Per Page
 Rs.AbsolutePage = Page    'Indicates The Page to Display

response.write "<tr><td colspan=2> You Search For <b>" & phone & "</b>. And We Found <b>" & rs.recordcount & "</b> results.</td></tr>"
response.write "<tr><td height=5> </td></tr>"

while (not rs.EOF And Rs.AbsolutePage = Page)
response.write "<tr><td> Name </td><td>" & StrCH(rs.fields(1)) & "</td></tr>"
response.write "<tr><td> Address </td><td>" & rs.fields(2) & "</td></tr>"

'-----------Function to bold the text-----------
Function StrCh(a)
 StrCh = Replace(a,phone,"<b>" & phone & "</b>")
End Function

'----------Table to Write Down the Pages-------------
'Rs.PageCount returns the number of pages.............
response.write "<table><td><center>Pages>> "

      For i = 1 to Rs.PageCount
  If i = Page then
   Response.Write "<font color=black>" & i & "</font>"
  Else
   Response.Write "&nbsp;<a href=phone_search.asp?pg="&i&"&query=" & sap & "&mysearch=" & phone & ">" & i & "</a>&nbsp;"
  End If
      Next
end if
%>
</table>



-------------
i have collected some nice avatars (37) and smileys (227) here you can download
http://www24.brinkster.com/webmastertool/download.html


Posted By: woodleyw
Date Posted: 10 June 2003 at 12:22pm

Thank you farrukh

I will try your code asap and let you know the results.

Thanks again!!

wlw

 

 



-------------
woodleyw


Posted By: farrukh
Date Posted: 10 June 2003 at 11:48pm
well i m waiting for your result if you have ne problem then i will be there....

-------------
i have collected some nice avatars (37) and smileys (227) here you can download
http://www24.brinkster.com/webmastertool/download.html



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net