Jump to content

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')

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.