Searching using a QueryString

Posted on 2005-04-28
Last Modified: 2010-04-17

I've got a list of headings displayed as links. Each link is a URL that includes a QueryString. For example...

SearchString.asp?Keywords=bkcase wood

When the "SearchString.asp" page is accessed, I'll do a select statemement based on the keywords and "voila", I'll produce a list of products based on the keywords and I'm good to go.

The problem occurs when although there are several products that have "bkcase" and "wood" in their descriptions, I don't get any matches. If I change the Keyword QueryString to just "bkcase" I'll get some matches, but I'm confident that I'm doing something wrong as far as my scripting is concerned, and I'm hoping someone can help me out before 9:00 this morning.
Question by:brucegust
    LVL 8

    Expert Comment

    Hi Bruce,

    have you tried to output your select statement using trace.writeline or some other method?
    I'm just checking to ensure that the select statement that is generated is in fact what you expect it to be.

    Reason is, I notice there's a space in the querystring (which is not acceptable), so a browser may be replacing this with an escape sequence ("%20") to make it conform.



    LVL 1

    Accepted Solution

    In case what doobdave mentioned isn't the problem;
    Are you in fact separating the keywords so that each becomes a separate search criteria, or just leaving the string as it is?

    Say the keyword "bkcase" resolves to this select statement:

    SELECT * FROM Products WHERE Description LIKE '%bkcase%'

    Unless you treat the keywords separately, including both keywords might yield:

    SELECT * FROM Products WHERE Description LIKE '%bkcase wood%'

    This asks the server to return any products whose description include *both* words, in that order. In this example, assuming we're using VBScript, we can do some magic by a simple replace of all instances of " " in the keyword string into "%' OR Description LIKE '%". This would yield:

    SELECT * FROM Products WHERE Description LIKE '%bkcase%' OR Description LIKE '%wood%'

    So, say your VBScript code says:

    "SELECT * FROM Products WHERE Description LIKE '%" & keywords & "%'"

    Then you could change that into:

    "SELECT * FROM Products WHERE Description LIKE '%" & Replace(keywords, " ", "%' OR Description LIKE '%") & "%'"

    Of course you'd have to modify this stuff to fit into your code. Since I haven't seen it I don't know how well this fits in :)

    Hope this is of some help.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Reading variable length EBCDIC in SAS 9 57
    Fibonacci challenge 11 61
    endX challenge 2 33
    stringclean challenge 26 43
    RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now