homepage Welcome to WebmasterWorld Guest from 54.196.199.46
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP MySQL report
sparkes




msg:4224191
 7:34 am on Oct 30, 2010 (gmt 0)

Hi Guys,
I have an array of data, that I want to compare against a field in my db, and drag out the items in the db that are NOT in the array..

Any ideas please...


TIA

 

Anyango




msg:4224200
 8:38 am on Oct 30, 2010 (gmt 0)

Hi Sparkes, Welcome to WebmasterWorld

select * from table where field not in ("item1","item2","item3")

and so on.

You can create a comma seperated list of your array items by using php's implode function

sparkes




msg:4224217
 10:55 am on Oct 30, 2010 (gmt 0)

perfect, it's too easy to start looking at complicated solutions, when a nice simple one liner is there..

Thank v much

sparkes




msg:4224221
 11:49 am on Oct 30, 2010 (gmt 0)

Ahh one possible stumbling block, the array can have over 1000 elements ! Will that be ok ?

enigma1




msg:4224467
 9:07 am on Oct 31, 2010 (gmt 0)

There is a mysql setting "max_allowed_packet" and puts a cap to the max length of your mysql statement. Default is 1MB so you should be ok.

Anyango




msg:4224740
 4:44 am on Nov 1, 2010 (gmt 0)

You might want to store those 1000+ items in a table and then run a join to grab only the results that dont have those vlaues. if the table is large then this IN() with 1k+ values might slow your query down

sparkes




msg:4224768
 8:37 am on Nov 1, 2010 (gmt 0)

Am pleased to say that it works ok, no significant speed issue. In reality it doesn't pull that much data..

The DB only has 9k rows, so nothing to worry about there..

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved