有没有办法添加到这个mysql查询,说明什么东西是'x'不在查询中包含它?
function get_newest_members() {
global $connection;
$query = "SELECT *
FROM ptb_users, ptb_profiles
WHERE ptb_users.account_type = \"member\" AND ptb_users.account_status = \"Active\" AND ptb_profiles.user_id = ptb_users.id
ORDER BY date_created DESC
LIMIT 0 , 6";
$newest_set = mysql_query($query, $connection);
confirm_query($newest_set);
return $newest_set;
}
我想在ptb_profiles.user_id ='99999'中添加排除?
这是可能的,如果是这样,有人可以告诉我。感谢。
答案 0 :(得分:2)
只需在您的情况下添加
SELECT ...
FROM ...
WHERE ... AND ptb_profiles.user_id <> '99999'
作为旁注,使用单引号而不是双引号,因此不需要\
$query = "SELECT *
FROM ptb_users INNER JOIN ptb_profiles
ON ptb_profiles.user_id = ptb_users.id
WHERE ptb_users.account_type = 'member' AND
ptb_users.account_status = 'Active'
ORDER BY date_created DESC
LIMIT 0 , 6";
答案 1 :(得分:1)
如果您要从结果中排除具有user_id 99999
的用户
添加
ptb_profiles.user_id != '99999'
答案 2 :(得分:1)
试试这个...
SELECT * FROM ptb_users, ptb_profiles WHERE ptb_users.account_type = \"member\" AND ptb_users.account_status = \"Active\" AND ptb_profiles.user_id = ptb_users.id AND ptb_profiles.user_id!='99999' ORDER BY date_created DESC LIMIT 0 , 6