2012-12-24 33 views
0

有沒有一種方法可以添加到這個mysql查詢來說明什麼是'x'不包括它在查詢中?MYSQL where where:where'X'Exclude?

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'?

這是可能的,如果是有人可以告訴我。謝謝。

回答

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

單引號如果你想排除有USER_ID 99999用戶結果

只需加上

ptb_profiles.user_id != '99999' 
+0

感謝偉大工程 –

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