khunjack Posted October 15, 2007 Share Posted October 15, 2007 Hi, I'll have a session array with growing numbers of id's. array = (2222,4444,32323,...} The records with these id's need to be excluded ... e.. ' .... id!=2222 and id!= 4444 ' Sure could build this querey via a loop. Question: Is there a better/shorter way in the WHERE Clause ??? ??? WHERE id!={array} ... ??? Thanks for every feedback Jack Link to comment https://forums.phpfreaks.com/topic/73367-solved-an-array-in-the-where-clause-possible/ Share on other sites More sharing options...
Barand Posted October 15, 2007 Share Posted October 15, 2007 <?php $array = (2222,4444,32323) $values = join (',', $array); $sql = "SELECT * FROM tablename WHERE id NOT IN ($values)"; Link to comment https://forums.phpfreaks.com/topic/73367-solved-an-array-in-the-where-clause-possible/#findComment-370152 Share on other sites More sharing options...
khunjack Posted October 15, 2007 Author Share Posted October 15, 2007 Barand, fantastic!!! Thank you very much for your straight forward solution .. big time appreciated. Jack Link to comment https://forums.phpfreaks.com/topic/73367-solved-an-array-in-the-where-clause-possible/#findComment-370239 Share on other sites More sharing options...
fenway Posted October 16, 2007 Share Posted October 16, 2007 Just remember this prevents the use of any index. Link to comment https://forums.phpfreaks.com/topic/73367-solved-an-array-in-the-where-clause-possible/#findComment-370660 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.