MySQL searching with array

Im trying to build an array full of email addresses:

[php]$email_addresses = array(‘[email protected]’, ‘[email protected]’);[/php]

Then use each one of the email addresses in a mySQL search
[php]
foreach ($email_addresses as $value) {
$results = array(mysql_query(‘SELECT ticketemailid FROM swticketemails WHERE email LIKE CONVERT(_utf8 ‘$value’ USING latin1) COLLATE latin1_swedish_ci’));
}
[/php]

Then finally store the results to an array that i will use later
[php]
while($row = mysql_fetch_assoc($results)) {
$data[] = $row;
}

print_r($data);
[/php]

But its not working. Can anyone help?

Problem is in this line:
[php]$results = array(mysql_query(‘SELECT ticketemailid FROM swticketemails WHERE email LIKE CONVERT(_utf8 ‘$value’ USING latin1) COLLATE latin1_swedish_ci’));[/php]

Do you want to create array of query results? If so, your $results value is re-defined on every iteration of loop. So, at the end of loop, $results is an array with just 1 value.

I would not recommend to do queries in loop. In your case I think you can use something like this:
[php]$results = mysql_query(“SELECT ticketemailid FROM swticketemails WHERE email IN (’”.implode("’,’",$email_addresses)."’)");[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service