Page 1 of 1

Excluding results from an array, in a query

Posted: Mon Jan 24, 2005 4:16 pm
by azz0r_
I have an array with ids
I have a query that needs to exclude those array ids

How?

Posted: Mon Jan 24, 2005 4:26 pm
by feyd

Code: Select all

SELECT * FROM table WHERE id NOT IN('1','3','200','634')

Posted: Mon Jan 24, 2005 4:29 pm
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)"
?

Posted: Mon Jan 24, 2005 4:31 pm
by feyd
there are functions and loops you can use to create that string.

viewtopic.php?t=29514 may be of interest..

Posted: Mon Jan 24, 2005 4:33 pm
by azz0r_
Hm I guess

Posted: Mon Jan 24, 2005 5:57 pm
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')";}