Hi folks, I need a little help here to get my little MySQL query to work. SELECT user_id, username, user_posts, user_avatar FROM cms_users WHERE username != 'X' ORDER BY user_posts DESC LIMIT 0,10 In the WHERE clause if I want to get the same result but not equal X, Y, and Z. More than just X. How do I do that?
SELECT user_id, username, user_posts, user_avatar FROM cms_users WHERE username NOT IN ('X','Y','Z') ORDER BY user_posts DESC LIMIT 0,10
Thanks for the hint. Now I take that concept and applied it in my php code below. Original code $result=$db->sql_query('SELECT a.user_id, a.username, a.user_posts, a.user_avatar FROM '.$user_prefix.'_users a ORDER BY user_posts DESC LIMIT 0,14'); Code (markup): I added NOT IN ('Admin', 'Helitown') Because I don't want to get the users Admin and Helitown and I get errorunexpected T_STRING. please see the modified code below. $result=$db->sql_query('SELECT a.user_id, a.username, a.user_posts, a.user_avatar FROM '.$user_prefix.'_users a WHER a.username NOT IN ('Admin', 'helitown')ORDER BY user_posts DESC LIMIT 0,7'); Code (markup): Can someone help me to avoid the error please? Thanks a lot
Try this: $result=$db->sql_query('SELECT a.user_id, a.username, a.user_posts, a.user_avatar FROM '.$user_prefix.'_users a WHER a.username NOT IN (\'Admin\', \'helitown\')ORDER BY user_posts DESC LIMIT 0,7'); or: $result=$db->sql_query("SELECT a.user_id, a.username, a.user_posts, a.user_avatar FROM ".$user_prefix."_users a WHER a.username NOT IN ('Admin', 'helitown')ORDER BY user_posts DESC LIMIT 0,7"); It's because the ' needs to be \' or use " instead.
I tried both ways and I got - so it is no longer a expected string problem A database error has occurred The webmaster has been notified of the error
SELECT user_id, username, user_posts, user_avatar FROM cms_users WHERE username NOT IN ('X','Y','Z') ORDER BY user_posts DESC LIMIT 0,10
Hi jestep, Actually, I found the problem. It is working now after I corrected the spelling of WHER to WHERE. Thanks a lot.