Wildcard WHERE Query Problem!!

Discussion in 'Databases' started by timallard, Jun 10, 2009.

  1. #1
    Hello,

    I currently have search functionality set up on a web tool i am building.
    I have a "keyword" search which uses the wildcard function to query a specific word.

    My problem is this:

    If i search by keyword and search say - "how". I only get results returned where the keyword was at the beginning.

    e.x.

    How will i make money?
    How will I get home tonight?

    and not

    do you know how to do this?
    she asked me how i can be so mean.

    see what i mean? How can i have the wildcard return results where there is an instance of that keyword mid sentence?

    here is my search string:

    elseif($SearchBy=='Keyword')
    {
    $query1= "SELECT * FROM curiosities WHERE Curiosity LIKE '".mysql_real_escape_string($Query). "%"."' $sort";
    $dropdownSearchBy = "Keyword";
    $dropdownSearchByValue = "Keyword";
    }


    Thanks!!!
     
    timallard, Jun 10, 2009 IP
  2. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #2
    Add another wildcard character "%" before the keyword, so statement is LIKE %keyword% :D
     
    Social.Network, Jun 11, 2009 IP
  3. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #3
    youuuuu rock. thank you much.
     
    timallard, Jun 11, 2009 IP
  4. chisara

    chisara Peon

    Messages:
    141
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Keep in mind that any created indexes can not be used since you are not matching from the start of the varchar.
     
    chisara, Jun 12, 2009 IP