Re: Select IN array?
| From: | James Tan | Date: | Sun, 15 Jul 2001 03:30:53 +0000 |
| Subject: | Re: Select IN array? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-57918@lists.php.net to get a copy of this message | ||
dear chris,
mysql does not support 'in' clause at the momment...
the only way to this is to use the loop to generate the sql syntax..
orr.. use the implode function... to join the array into 1 string separated by
the first parameter...
$catsql = implode("or cid=", $catids);
$catsql = ((strlen(catsql)>0)? substr(catsql, 3, strlen(catsql)): "");
$catsql = "select * from categories where " . $catsql;
Chris Lott wrote:
> I have an array of id numbers ($catids). I would like to select from the
> mysql database all records where cid is in that array.
>
> This syntax fails:
> select * from categories
> where cid in $catids
>
> What is the correct way to do this? It can be done outside of a loop, can't
> it?
>
> c