SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast codlib's Avatar
    Join Date
    Jan 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Escaping wildcard characters like % in mysql "LIKE" statement.

    Hi

    Can anyone explain, how i can escape wildcard chars like % in the mysql like statement.

    For example consider the below query

    $keyword = '100';
    $query = "SELECT * FROM `someTable` WHERE `keyword` LIKE '%".$keyword."%' ";

    In the above case it will work fine and will list all records matching 100. Now i want to list all records matching the keyword '100%'. I want 100% to matches one-hundred-percent and not just any string starting with a hundred. How will i do this. I have tried to escape it using addslashes/mysql_real_escape. Both will not escape %.

    Can anyone suggest a solution with an example.

    Many Thanks
    Jans

  2. #2
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Backslash ' \ ' should work.

    $query = "SELECT * FROM `someTable` WHERE `keyword` LIKE '%".$keyword."\%' ";

  3. #3
    SitePoint Enthusiast codlib's Avatar
    Join Date
    Jan 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got the answer from another thread.

    http://stackoverflow.com/questions/3...sql-wild-cards


Bookmarks

Posting Permissions

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