Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Possible Duplicate:
PHP/MYSQL using an array in WHERE clause

I have an array called $ids:

Array ( [0] => 14  [1] => 15 [2] => 16 [3] => 17 [4] => 18 [5] => 19)

I want to select from table Users where ID matches any value on the array. How can this be done?

share|improve this question

marked as duplicate by Michael Berkowski, Aurelio De Rosa, Aron Rotteveel, ajreal, Matt Nov 21 '11 at 9:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 11 down vote accepted

Something like this:

$values = implode(',', $ids);
$sql = "SELECT * FROM Users WHERE ID IN ($values)";
share|improve this answer
Thanks V2p... just what I was looking for today!!! – Daniel Hunter Jan 25 '12 at 0:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.