Jump to content

[SOLVED] search db with array


digitalgod

Recommended Posts

hey guys,

 

say I have an array of emails that I'd like to verify if they exist in a db, would there be a better way than having a select query for each email?

 

something other than

 

<?

for ($i=0; $i < $max; $i++)
{
  $query = "SELECT id WHERE email = '" . $aEmail[$i] . "' "
  $result = mysql_query($query) or die(mysql_error());
  $numRows=mysql_num_rows($result);
  
  // etc...
}
?>

Link to comment
https://forums.phpfreaks.com/topic/108775-solved-search-db-with-array/
Share on other sites

Do it sasa's way.

 

I forgot the outer quotes in the implode.  The implode will take your array and make it into a comma and quote separated list, the goal being to make your query string look like this:

 

select id from table where id in ('blah','someotherblah','moreblah')

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.