PHP MySQL query rejecting results that are in an array

How would I go about executing a MySQL query of say Limit 10 but only returning results that are not in an array? Kind of like the NOT IN () mysql function but not in a PHP array?

LVL 10
stormistAsked:
Who is Participating?
 
zreakCommented:
How about putting the php-array in the sql-query? By sorting out the info you don't want as quickly as possible will the most effective way to solve this.

mysql> use test
mysql> create table test (num int);
mysql> insert into test values (1), (2), (3), (4);
mysql> insert into test values (5), (6), (7), (8);

<?
mysql_connect ("localhost", "", "");
mysql_select_db ("test");
$not = array (1,2,3);
$data = implode (",", $not);
$res = mysql_query ("SELECT num FROM test WHERE num NOT IN ($data)");
while ($info[] = mysql_fetch_array($res));
print_r($info);
?>

Returns the values (4,5,6,7,8)
0
 
stormistAuthor Commented:
Wow is it really that simple? I'm trying it now! :)
0
 
CtrlAltDlCommented:
Yea, but it tends to be really slow!
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
stormistAuthor Commented:
hmm any way to speed it up?
0
 
CtrlAltDlCommented:
Did you try it out?  It maybe fast enough for your application.
0
 
stormistAuthor Commented:
Well I am applying it to a few places, so it'll prolly be a day or two until i fully test it out. Was just leaving thread open a little longer to get more input and possibilities I appreciate any comments you might have!
0
 
CtrlAltDlCommented:
I've had "NOT IN" worked well in MySQL and a different query with "NOT IN" in MSAccess that was way too slow, but it could have just been the amount of data or just the fact that MSAccess is in inferior (probably the latter).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.