SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Several columns in the WHERE clause

    In the following query I would like to search for more than `name`, for example: WHERE `name` `brand` `size` LIKE '%q%'
    but, I don't know the correct syntax to follow.

    Code MySQL:
    SELECT *
    FROM (
              SELECT *
              FROM `products`
              WHERE `name`
              LIKE '%q%'
              AND `user_id` = '$user_id'
          )
              AS results
    WHERE    `status` = 0
    OR       `status` = 1
    OR       `status` = 2
    OR       `status` = 3

    I need help

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,277
    Mentioned
    120 Post(s)
    Tagged
    1 Thread(s)
    If I understand you, this should get you what you want (or at least push you in the right direction)...

    Code MySQL:
    SELECT *
      FROM `products`
     WHERE (`name` LIKE '%q%' OR `brand` LIKE '%q%' OR `size` LIKE '%q%')
       AND `user_id` = '$user_id'
       AND `status` IN (0, 1, 2, 3)
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    It's so much simpler, and it worked great. Thanks so much.


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
  •