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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post

    using LIKE in 2 rows?

    I have the following snippet of code:

    Code:
    $query = "select * from offers where name like \"%$trimmed%\"  
      order by name"; // EDIT HERE and specify your table and field names for the SQL query
    how would i make it so its
    Code:
    where name like \"%$trimmed%\" AND country like \"%us%\"
    thanks

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,799
    Thanks
    78
    Thanked 4,410 Times in 4,375 Posts
    You just did.

    Excepting that normally we use apostrophes to delineate strings in SQL code. (Some databases, other than MySQL won't even accept quotes.)

    Code:
    $query = "SELECT * FROM  offers WHERE name LIKE '%$trimmed%' AND country LIKE '%us%' ORDER BY name";
    Why didn't you just try it?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    bahahaha, found the error. i was putting country when it was countries
    Last edited by markman641; 08-27-2011 at 07:06 PM.


  •  

    Posting Permissions

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