[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP MySQL query rejecting results that are in an array

Posted on 2006-04-04
7
Medium Priority
?
279 Views
Last Modified: 2006-11-18
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?

0
Comment
Question by:stormist
  • 3
  • 3
7 Comments
 
LVL 3

Accepted Solution

by:
zreak earned 1000 total points
ID: 16378701
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
 
LVL 10

Author Comment

by:stormist
ID: 16378910
Wow is it really that simple? I'm trying it now! :)
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 16385109
Yea, but it tends to be really slow!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 10

Author Comment

by:stormist
ID: 16388040
hmm any way to speed it up?
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 16388264
Did you try it out?  It maybe fast enough for your application.
0
 
LVL 10

Author Comment

by:stormist
ID: 16388337
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
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 16389088
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month18 days, 15 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question