PDA

View Full Version : Query not returning the results I want


harmor19
05-30-2007, 06:12 PM
I don't know what I'm doing wrong.

I want to make a query that will return results if the column "required" is 2 or 3 but the column "type" cannot be "input" or "textarea".
$showfields = $db->query_read("SELECT * FROM ".TABLE_PREFIX."profilefield
WHERE required = '2' OR required = '3'
AND (type != 'input' OR type != 'textarea') ");

It's returning row 6 even though the type is "textarea".

Eikinskjaldi
05-30-2007, 08:46 PM
I don't know what I'm doing wrong.

I want to make a query that will return results if the column "required" is 2 or 3 but the column "type" cannot be "input" or "textarea".
$showfields = $db->query_read("SELECT * FROM ".TABLE_PREFIX."profilefield
WHERE required = '2' OR required = '3'
AND (type != 'input' OR type != 'textarea') ");

It's returning row 6 even though the type is "textarea".

Heh, the problem is your logic. (type != 'input' OR type != 'textarea') is always true, because input will ALWAYS either not be input or not be textarea.

Three of solutions....
AND type not in ("input","textarea")

or

AND !(type="input" or type="textarea)

or

AND (type !="input" and type!="txtarea")

harmor19
05-30-2007, 10:03 PM
I also had to wrap the two "required" in parenthesis.

Thanks.