Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

This question already has an answer here:

I'm trying to make sql query for rows matching values in a php array.

Essentially I have an array like

$userIDs[0] = 23456;
$userIDs[1] = 42901;
$userIDs[2] = 82731;
$userIDs[3] = 23921;

And want to perform a single SQL query to get rows matching this array

SELECT * FROM users WHERE userID IN $userIDs

Is there an easy way to do this? Or do I have to manually construct the query string?

share|improve this question

marked as duplicate by Levi Morrison, PeeHaa php Aug 28 '14 at 16: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.

up vote 11 down vote accepted

Use implode function ie

$QueryStr = "SELECT * FROM users WHERE userID IN (".implode(',', $userIDs).")";
share|improve this answer

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