Hi James!
On Sun, 15 Jul 2001, James Tan wrote:

> 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...

huh?
teo@teo:/x > mysql test 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 155 to server version: 3.23.39

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> desc stock;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| item   | varchar(17) | YES  |     | NULL    |       |
| num    | varchar(4)  | YES  |     | NULL    |       |
| weight | varchar(7)  | YES  |     | NULL    |       |
| price  | varchar(7)  | YES  |     | NULL    |       |
| date   | datetime    | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> select * from stock where num in (1,3);
+------+------+--------+-------+---------------------+
| item | num  | weight | price | date                |
+------+------+--------+-------+---------------------+
| foo  | 1    | 2kg    | 123   | 2001-06-24 21:08:04 |
| bar  | 3    | 7kg    | 1234  | 2001-06-24 21:08:13 |
+------+------+--------+-------+---------------------+
2 rows in set (0.00 sec)

> > 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
do :
$catids = implode(',',$catids);
$qs ="SELECT * FROM categories WHERE cid IN ($catids)";

-- teodor

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to