Re: Finding array in MySQL (I'm not asking the right question)
| From: | Sophie Mattoug | Date: | Tue, 02 Dec 2003 15:31:45 +0000 |
| Subject: | Re: Finding array in MySQL (I'm not asking the right question) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-171588@lists.php.net to get a copy of this message | ||
You can do something like
$str = "'".implode("', '", $arr)."'";
$query = "SELECT * FROM table WHERE id IN ($str)";
Hope this helps,
--
Cordialement,
---------------------------
Sophie Mattoug
Développement web dynamique
sophie@mattoug.net
---------------------------
Dave G wrote:
>PHP Gurus,
> What I'm trying to do must be both common and simple, but I'm
>not asking the question right because I can't find the answers in Google
>or the online PHP manual using the search words like array, find, PHP,
>MySQL, etc...
> I have an array, and I want to select the fields in a table that
>match the contents of the array.
> The array consists of a set of user IDs. I want to find their
>emails from the table in a MySQL database which stores all their contact
>information. Sounds simple, right?
> Well, "SELECT email FROM table WHERE id = " . $array . ")";
>isn't cutting it.
> I'm a total beginner, but I can understand why this doesn't work
>without being able to fix it. The data inside the array needs to be
>extracted into the set of ids it contains so that MySQL can read it. So
>I could run a while() loop and query the database for each id in the
>array, but that's obviously totally inefficient.
> There must be a command which handles this kind of thing. It's
>not explode(), it's not in_array()... I know what I'm after, but I just
>can't come up with the search term or phrasing which will allow a search
>engine to help me find it.
> Can someone please point me in the right direction?
>
>