SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    377
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question PHP MYSQL LIKE query with several items

    Can anyone tell me how I would set up a query so that it will select rows based on where a column contains any one of 5 values. For example if name field contains john or mark or raymond. Sounds like it should be straight forward but I can't think how I would code that. What I use for a single option would be this:

    SELECT * FROM table WHERE Name LIKE '%John%'

    Thanks for any help in advance with this.

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,897
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    Just keep adding them with OR in between:

    SELECT * FROM table WHERE Name LIKE '%John%' OR Name LIKE "%mark%" OR Name LIKE "%raymond%"

    etc
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    377
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent. Thanks!! Obviously having a blonde moment!! Much appreciated.


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
  •