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
Who is Participating?
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));

Returns the values (4,5,6,7,8)
stormistAuthor Commented:
Wow is it really that simple? I'm trying it now! :)
Yea, but it tends to be really slow!
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?
Did you try it out?  It maybe fast enough for your application.
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!
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).
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.