Searching fields using mid

Results 1 to 2 of 2

Thread: Searching fields using mid

  1. #1
    Join Date
    Dec 1969

    Default Searching fields using mid

    I would like to search my database with a partial string. I know how to assign the database field to a variable and I know how to loop through the fields in the database. I cannot figure out how to search the string for a partial match. For instance, if the user is searching for "improvements", I want "RAK Improvements" to be a match. Any guidance would be appreciated.

  2. #2
    Join Date
    Dec 1969

    Default Please, NOT Mid!

    That would be HORRIBLY slow!<BR><BR>Learn about the InStr (and InStrRev) function!<BR><BR>&#060;%<BR>text = RS("dbFieldName")<BR>found = InStr( text, keyword )<BR>If found &#062; 0 Then<BR>&nbsp; &nbsp; Response.Write "found a match"<BR>End If<BR>%&#062;<BR><BR>HOWEVER...<BR><BR>You *REALLY* don&#039;t want to do *THIS* either! WAY WAY WAY too slow!<BR><BR>Use SQL and let the DB do the search for you!<BR><BR>&#060;%<BR>SQL = "SELECT * FROM table WHERE someField LIKE &#039;%" & keyword & "%&#039; "<BR>Set RS = yourConnection.Execute( SQL )<BR>... and now the RS has *only* records that have a match in that field! ...<BR>%&#062;<BR><BR>If you want to *HIGHLIGHT* the found words, you could do (after that SQL query):<BR><BR>&#060;%<BR>text = RS("someField")<BR>text = Replace( text, keyword, "&#060;B&#062;" & keyword & "&#060;/B&#062;" )<BR>...<BR>%&#062;<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts