我试图从Mysql_query中排除一个“ID”,但它仍然返回所提到的ID。 这个ID是“21”,但查询返回的却是“21”,这不是我想要的结果。 我在Mysql中有拼写错误吗?
("SELECT * FROM `gallery` WHERE `gallery_id` NOT IN ('$notgallery')") or die (mysql_error());
function not_gallery($pic){
$pic = $_GET['id'];
$id = explode(".", $pic);
$notgallery = $id;
$notg = mysql_query("SELECT * FROM `gallery` WHERE `gallery_id` NOT IN ('$notgallery')") or die (mysql_error());
while($not_row = mysql_fetch_assoc($notg)){
$notgimage[] = array(
'id' => $not_row['gallery_id'],
'user' => $not_row['user_id'],
'name' => $not_row['name'],
'timestamp' => $not_row['timestamp'],
'ext' => $not_row['ext'],
'caption' => $not_row['caption'],
);
}
print_r($notgimage);
}
我使用print_r打印出查询结果,仍然返回“21”,这是我排除掉的或者我认为我已经排除掉了的。
Array ( [0] => Array ( [id] => 21 [user] => 18 [name] => NotDeojeff [timestamp] => 1367219713 [ext] => jpg [caption] => asd ) [1] => Array ( [id] => 22 [user] => 18 [name] => NotDeojeff [timestamp] => 1367225648 [ext] => jpg [caption] => Ogre magi )
explode
的结果,它会给你一个数组。你需要再次使用逗号作为粘合剂来进行implode
操作。 - andrewsi$notgallery
是一个数组。我假设不需要.jpg
扩展名,所以我认为你的意思是"WHERE gallery_id != {$notgallery[0]}"
。 - gen_EricIN ('12,21')
与IN(12,21)
不同。 - andrewsi