digitalgod Posted June 5, 2008 Share Posted June 5, 2008 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... } ?> Quote Link to comment https://forums.phpfreaks.com/topic/108775-solved-search-db-with-array/ Share on other sites More sharing options...
digitalgod Posted June 5, 2008 Author Share Posted June 5, 2008 Don't mind the missing FROM in my $query example. I could have sworn there was a Modify button but all I see is Quote... Quote Link to comment https://forums.phpfreaks.com/topic/108775-solved-search-db-with-array/#findComment-558014 Share on other sites More sharing options...
.josh Posted June 5, 2008 Share Posted June 5, 2008 $list = implode (',',$aEmail); $query = "select id from table where id in('$list')"; Quote Link to comment https://forums.phpfreaks.com/topic/108775-solved-search-db-with-array/#findComment-558061 Share on other sites More sharing options...
sasa Posted June 5, 2008 Share Posted June 5, 2008 $list = implode (',',$aEmail); $query = "select id from table where id in('$list')"; $list = implode ("','",$aEmail); $query = "select id from table where id in('$list')"; Quote Link to comment https://forums.phpfreaks.com/topic/108775-solved-search-db-with-array/#findComment-558067 Share on other sites More sharing options...
digitalgod Posted June 5, 2008 Author Share Posted June 5, 2008 thanks Crayon I'll give it a shot. why the "" sasa? I'll try it both ways Quote Link to comment https://forums.phpfreaks.com/topic/108775-solved-search-db-with-array/#findComment-558068 Share on other sites More sharing options...
.josh Posted June 5, 2008 Share Posted June 5, 2008 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') Quote Link to comment https://forums.phpfreaks.com/topic/108775-solved-search-db-with-array/#findComment-558079 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.