Re: [PHP] Re: Select IN array?

2001-07-15 Thread teo

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]




[PHP] Re: Select IN array?

2001-07-14 Thread James Tan

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


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