Posted By: Quinn
Given an array of ids
$galleries = array(1,2,5) I want to have a SQL query that uses the values of the array in its WHERE clause like:
SELECT * FROM galleries WHERE id = /* values of array $galleries... eg. (1 || 2 || 5) */
How can I generate this query string to use with MySQL?
BEWARE! This answer contains a severe SQL injection vulnerability. Do NOT use the code samples as presented here, without making sure that any external input is sanitized.
$ids = join("','",$galleries); $sql = "SELECT * FROM galleries WHERE id IN ('$ids')";