Q:

PHP/mySQL - Select WHERE multiple values in an associative array

$skuArray = array(00240=>123,00241=>456);
$getSkus = mysql_query("SELECT sku FROM data WHERE sku IN($skuArray)");

My above code doesn't work, how can I make it SELECT all sku's FROM data WHERE sku = any of the key names in $skuArray? (00240 and 00241 in this case)
Hope this makes sense, Thank You.

A:

Try this:
<?php
$skuArray = array('00240'=>123, '00241'=>456);

$inSkus = array();

foreach (array_keys($skuArray) as $key)
{
    $inSkus[] = '"' . $key . '"';
}

$sql = 'SELECT sku FROM data WHERE sku IN (' . implode(', ', $inSkus) . ')';

echo $sql;

You need to have the keys as strings and you then need to wrap them in parentheses for the SQL query.

