I am trying to check for 2 empty variables in a MySQL statement but I can seem to get the syntax quite right for it. Here is what I have now and it keeps giving me an error. Can anyone please tell me how I can do this properly?
SELECT threads, userid, username, usergroupid
FROM " . TABLE_PREFIX . "user
WHERE
" . iif(!empty($exuserids), "AND userid NOT IN ($exuserids)") . "
" . iif(!empty($exgroups), "AND usergroupid NOT IN ($exgroups)") . "
ORDER BY threads DESC
LIMIT 1
Use:
There needs to be a WHERE clause before you specify “AND …” – the
1 = 1will be optimized out. It’s a trick used for dynamic SQL to make WHERE clause concatenation easier.