Excluding results from an array, in a query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
azz0r_
Forum Commoner
Posts: 27
Joined: Mon Jan 24, 2005 4:15 pm

Excluding results from an array, in a query

Post by azz0r_ »

I have an array with ids
I have a query that needs to exclude those array ids

How?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

SELECT * FROM table WHERE id NOT IN('1','3','200','634')
azz0r_
Forum Commoner
Posts: 27
Joined: Mon Jan 24, 2005 4:15 pm

Post by azz0r_ »

The array isnt something I can define though as it differs from user to use

Can I not do "ID NOT IN($array)"
?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there are functions and loops you can use to create that string.

viewtopic.php?t=29514 may be of interest..
azz0r_
Forum Commoner
Posts: 27
Joined: Mon Jan 24, 2005 4:15 pm

Post by azz0r_ »

Hm I guess
azz0r_
Forum Commoner
Posts: 27
Joined: Mon Jan 24, 2005 4:15 pm

Post by azz0r_ »

Final code

Code: Select all

if($f)
	{$string = str_replace(',', '', $f);
	$string = implode("', '", $string); 
	$string = substr("$string", 3);
	$string = "AND f.fid NOT IN($string')";}
Post Reply