49

我想排除这些具有以下名称的专辑:

$ban_album_names = array('Wall', 'Profile', 'Cover', 'Instagram');

如何正确书写,

SELECT * FROM albums WHERE name NOT IN ???

我怎样才能让它在数组中查找,如果名称匹配它应该!= 行

4

2 回答 2

92

试试这个:

$sql = "SELECT *
    FROM albums
    WHERE name NOT IN ( '" . implode( "', '" , $ban_album_names ) . "' )";
于 2012-09-01T18:45:05.847 回答
36

MySQL代码是

SELECT * FROM albums WHERE name NOT IN ('Wall', 'Profile', 'Cover', 'Instagram')
于 2012-09-01T18:42:57.530 回答