Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2009
    Posts
    186
    Thanks
    72
    Thanked 2 Times in 2 Posts

    Question about SEARCHING - Searching Any Word

    Hello. I am building an advanced search feature on my website. The way I am designing it is to allow 3 different types of searches: Any Words, Any Portion of a Word, and Exact Phrase.

    This is how I do exact phrase:
    PHP Code:
    $sql mysql_query("select * from gamesdb where search_keywords like '$term_sanitized' "); 
    This is how I do Any Portion of a Word: (Same as above except I added the wildcard '%' symbols)
    PHP Code:
    $sql mysql_query("select * from gamesdb where search_keywords like '%$term_sanitized%' "); 
    My question is: how can you search for full words only? For example, if the name "John Smith" is in my database, I want that entry to display if the user searches for 'John', 'Smith', or 'John Smith', but NOT if he searches for a portion of it, something like 'Joh' or 'ith'.

    Thank you in advance for your help!
    Last edited by skcin7; 09-01-2009 at 06:42 PM. Reason: Not Clearly Explained

  • #2
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    remove the front % or back % from the wildcard. Play with that see if it works.

  • #3
    Regular Coder
    Join Date
    Jul 2009
    Posts
    186
    Thanks
    72
    Thanked 2 Times in 2 Posts
    Hi thanks for the reply. I have been messing with it for a while, which is why I posted my question here. I currently have a functional search bar, however it is not how I want it.

    What I want, is to only show entries that match a full word that the user entered. For example, searching "Mario" will return "Super Mario 2" and similar entries. Similarly, searching "Super 2" will return "Super Mario 2" and similar entries. However, searching "Mar" will return nothing.

    I've seriously been messing with it all day today and searching Google but I am very much new to PHP and SQL and I just can't figure it out. I imagine the solution is quite simple. Thanks in advance for any more help provided.


  •  

    Posting Permissions

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