+ Reply to Thread
Results 1 to 3 of 3

Thread: PHP equivalent to MySQL IN statement?

  1. #1
    Barn Regular bryceowen is on a distinguished road bryceowen's Avatar
    Join Date
    Sep 2008
    Location
    Jacksonville, FL
    Posts
    93
    Rep Power
    4

    PHP equivalent to MySQL IN statement?

    Right now, I have several pages that use IF statements to compare a variable against different values:
    Code:
    if(($value=='a')||($value=='b')||($value='c')){
    
    Is there anything in PHP similar to MySQL's IN() clause? It would help me clean up a lot of code.

  2. #2
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    I'm no PHP'er, but something like
    Code:
    strpos("a!b!c!", $value . "!") >= 0
    
    might do what you want. strpos will return of the position of $value! in the string "a!b!c!", or FALSE if the string is not found. I append the funky character "!" to the value to prevent a value of 'ab' from matching. Not sure how PHP interprets IF FALSE >= 0 however.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  3. #3
    Barn Regular bryceowen is on a distinguished road bryceowen's Avatar
    Join Date
    Sep 2008
    Location
    Jacksonville, FL
    Posts
    93
    Rep Power
    4

    Looking at your solution, I just realized I could do a regx check against the variable. Thanks again, Wolffy!

+ Reply to Thread

Similar Threads

  1. sql statement with an iif statement inside
    By arloguth in forum Microsoft Access
    Replies: 7
    Last Post: June 7th, 2009, 11:31 PM
  2. best way to bind values to sql statement?
    By Centurion in forum ASP Development
    Replies: 11
    Last Post: March 17th, 2009, 07:45 AM
  3. Pagination, using PHP and MySQL
    By don94403 in forum PHP Development
    Replies: 0
    Last Post: December 13th, 2008, 01:01 AM
  4. UBound and LBound equivalent for PHP?
    By bryceowen in forum PHP Development
    Replies: 1
    Last Post: September 12th, 2008, 10:30 AM
  5. iif statement
    By Barkol in forum Microsoft Access
    Replies: 4
    Last Post: June 6th, 2008, 12:12 AM

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

SEO by vBSEO