Array, database... help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
megaming
Forum Commoner
Posts: 27
Joined: Wed Dec 25, 2002 12:31 pm

Array, database... help!

Post by megaming »

Hi,

I want to split some numbers that are seperated by commars (,) and put them into an array.

I then want to select each record from a database which has the same id as the numbers in the array.

I think this would be done by a split, then a for or a while.

I'm not sure though... can someone help me out?

Thanks!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if the numbers are separated by , the string is perfectly suited for expr IN (value,...) (http://www.mysql.com/doc/en/Comparison_Operators.html#IDX1118)
e.g.

Code: Select all

$query = 'SELECT field FROM table WHERE id IN ('.$numbers.')';
Post Reply