#1
  1. King of da Wackos
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Location
    Planet Zeekois
    Posts
    92
    Rep Power
    0

    Question PHP search query way too restrictive


    if($_GET['order'] == 'Link') {
    $query = "SELECT Link FROM XXXXXX WHERE `Title` LIKE '%{$search}%' ORDER BY $order ASC LIMIT $start_from, 50";
    }

    For example...

    Search for: Google Friendly Sites

    spits a result out with 'Google Friendly Sites'.

    Search for: Google Sites

    generates nothing. How do you make it so if you make a search with more than one word, if the words are there it shows up in the results, even if it's not in the exact order?


    Also, can something be put in the query to require there be three characters or more in the search?

    Comments on this post

    • requinix agrees : you're not supposed to be proud of being a spammer!
    Just a coding n00bie, and is most likely a SPAMMER, and a traitor to da cause!!!

    Um, can some one give me some red??!! I got '1 points total' so I need just one negative rep to get back to being most likely a SPAMMER, and a traitor to da cause!!!

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,232
    Rep Power
    593
    This has nothing to do with PHP. What database engine are you using so this can be moved to the appropriate DB forum?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,754
    Rep Power
    9397
    For the "three characters or more", that's something you have to enforce in code. [mb_]strlen() is your friend.

    As for the rest? I'm going to make an educated guess that you're using MySQL...

    [edit] Oh, and now your sig is wrong.
    Last edited by requinix; April 29th, 2013 at 02:57 PM.
  6. #4
  7. King of da Wackos
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Location
    Planet Zeekois
    Posts
    92
    Rep Power
    0
    A php script using mySQL.

    Originally Posted by requinix
    [edit] Oh, and now your sig is wrong.
    Gah!! Can some one fix that!! I got 1 point total now so I only need one person to disagree to knock me back down to where I should be at!
    Just a coding n00bie, and is most likely a SPAMMER, and a traitor to da cause!!!

    Um, can some one give me some red??!! I got '1 points total' so I need just one negative rep to get back to being most likely a SPAMMER, and a traitor to da cause!!!

  8. #5
  9. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,301
    Rep Power
    7170
    The closest you can get with built-in MySQL functions is MATCH_AGAINST, although that comes with a number of restrictions and limitations. Beyond that, it gets fairly complicated fairly fast.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  10. #6
  11. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,027
    Rep Power
    4210
    Originally Posted by Nintendo
    How do you make it so if you make a search with more than one word, if the words are there it shows up in the results, even if it's not in the exact order?
    i disagree with gw1500se's comment that this has "nothing to do with php"

    you do it by using php to split up the search string into words, and generating the sql to search for multiple individual words

    so in the example you gave...
    Code:
    WHERE Title LIKE '%Google%' 
       OR Title LIKE '%Friendly%'
       OR Title LIKE '%Sites%'
    Originally Posted by Nintendo
    Also, can something be put in the query to require there be three characters or more in the search?
    well, i guess, but it would be far better to do that in php too

    Last edited by r937; April 29th, 2013 at 06:05 PM.
    r937.com | rudy.ca
    please visit Simply SQL and buy my book

IMN logo majestic logo threadwatch logo seochat tools logo