Results 1 to 3 of 3

Thread: php equivalent for SQL IN(...) clause

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default php equivalent for SQL IN(...) clause

    I would like to be able to say in php something like this:

    Code:
    if(field1 != 0 AND field2 NOT IN (5,8,10) {
      do something;
    }
    Is there anything like this in php? or do I have to say:

    Code:
    if(field1 != 0 AND (field2 != 5 AND field2 != 8 AND field2 != 10)){
      do something;
    }
    The second way seems so messy. Thanks!

  2. #2
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    PHP Code:
    $arr = array(5,8,10);
    if(
    $field1 != AND !in_array($field2$arr)) {
      do 
    something;


  3. The Following User Says Thank You to techietim For This Useful Post:

    kuau (04-08-2009)

  4. #3
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    Exactly what I needed... thanks, techietim!

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
  •