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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Searching for exact term or no result

    Hello folks,

    First time posting here and I am hoping some of you fine people could help me with a problem I am having.

    I have a full text search box that if I type even the letter 'j' it will pull in every record with the letter 'j'.

    Basically I cant figure out how to search for a term and only that term so if I type 'joe blogs' joes record will appear and if i type 'j' nothing will appear.

    My apologies as I cant think of how to explain it.

    The code I am using at the moment is:

    //Search Query
    $sql = mysql_query("SELECT * FROM UserList WHERE Name like '%$search%'");

    Many Thanks,

    Peter

  • #2
    New Coder
    Join Date
    Mar 2011
    Posts
    57
    Thanks
    5
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by pquinn View Post
    Hello folks,

    First time posting here and I am hoping some of you fine people could help me with a problem I am having.

    I have a full text search box that if I type even the letter 'j' it will pull in every record with the letter 'j'.

    Basically I cant figure out how to search for a term and only that term so if I type 'joe blogs' joes record will appear and if i type 'j' nothing will appear.

    My apologies as I cant think of how to explain it.

    The code I am using at the moment is:

    //Search Query
    $sql = mysql_query("SELECT * FROM UserList WHERE Name like '%$search%'");

    Many Thanks,

    Peter
    Probably a bit of a random guess, I'm new to PHP too, but where it says "name like" change it just to "name"

  • #3
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lol now that does make me feel stupid, worked perfectly Thanks for helping

  • #4
    New Coder
    Join Date
    Mar 2011
    Posts
    57
    Thanks
    5
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by pquinn View Post
    lol now that does make me feel stupid, worked perfectly Thanks for helping
    Hehe, no problem, sometimes common sence is all that is neccessary.

  • #5
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have the same problem. Could you let me know how did you solved it? Thanks

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You simply change the WHERE condition to not use like.
    Code:
    WHERE Name LIKE '%j%'
    // becomes
    WHERE Name = 'j'
    This of course has nothing to do with PHP as this is a SQL issue in search criteria.


  •  

    Posting Permissions

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