Re: In_Array in Query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kevin Murphy wrote:
I'm wondering if something like this is possible, where $array is an array.

$query = "select id from table where in_array(row,'$user_area')";

Is it possible to see if the value of a particular row is in an array? I know I could create a loop where it would go through each one, but I was hoping not to do something like the following:

$query = "select id from table where row = $user_area[0] OR row = $user_area[1] OR row = $user_area[2]"

Not really.

There is a slight shortcut:

$query = "select id from table where row in (" . implode(',', $user_area) . ")";

which does much the same (your db converts it internally).

That assumes 'user_area' only contains numbers, any strings in there and you'll have to create a loop so you can use the proper escaping function (depending on your db).

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux