Results 1 to 2 of 2

Thread: MySQL WHERE clause using LIKE

  1. #1
    Join Date
    Jul 2008
    Posts
    2

    MySQL WHERE clause using LIKE

    I have a column in a table that contains domain names. I want to use the $_SERVER['HTTP_HOST'] value to see if the domain name exists in my table. If one of the rows has 'abcdomain.com' in the domain name column, how do I code the WHERE LIKE clause to check for true against 'abcdomain.com', or 'www.abcdomain.com', or test.abcdomain.com', etc.?

    My current PHP select statement looks like the following and is only returning true on the 'abcdomain.com':

    SELECT * FROM myTable WHERE domainName LIKE '%".strtolower($_SERVER['HTTP_HOST'])."' LIMIT 1


    Note: I recognize that the problem is my "haystack" string is smaller than the "needle" string in some instances. So I need to figure a way to handle that or otherwise swap the clause to something like this:

    '%".strtolower($_SERVER['HTTP_HOST'])."' LIKE domainName


    Thank you for your help.

  2. #2
    Join Date
    Jul 2008
    Location
    Belgium
    Posts
    17
    Hello

    By using LIMIT 1 means you want to see 1 result.

    Greetings
    ld_be

Posting Permissions

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