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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stormistAuthor Commented:
Wow is it really that simple? I'm trying it now! :)
Yea, but it tends to be really slow!
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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).
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.