 |

03-20-2006, 08:03 PM
|
|
SEO Almost
|
|
Join Date: Sep 2004
Posts: 114
|
|
|
AND query
select cid,login_time from users where active = 1 AND banned = 0 AND kicked = 0
All those conditions are being met and it's not returning the row. I tried parenthesis and that didn't work.
__________________
www.harddrivecaddy.com
|

03-21-2006, 07:19 AM
|
|
SEO
|
|
Join Date: Sep 2005
Location: Fort Collins, Colorado
Posts: 446

|
|
|
Are active banned and kicked bits/booleans? If so you may try true and false instead (without quotes). Depending of the version of SQL your using, what is taken will be different, even though 1 and 0 should work fine.
|

03-21-2006, 09:09 AM
|
|
SEO Almost
|
|
Join Date: Sep 2004
Posts: 114
|
|
|
Yeah, it is a boolean. I'll try that when I get home.
__________________
www.harddrivecaddy.com
|

03-21-2006, 12:49 PM
|
|
SEO Almost
|
|
Join Date: Sep 2004
Posts: 114
|
|
|
I tried that and it didn't work.
CREATE table users (
cid varchar(10),
active int(1),
login_time DATETIME,
kicked bool,
banned bool,
listenonly int(1),
audio varchar(30),
request_audio bool,
comments varchar(255)
);
__________________
www.harddrivecaddy.com
|

03-21-2006, 01:16 PM
|
|
SEO
|
|
Join Date: Sep 2005
Location: Fort Collins, Colorado
Posts: 446

|
|
|
I'm assuming this is MySQL. Do a describe on your table:
DESC users;
and see if the bool gets converted into a "tinyint(1)"
Then retest it. I just testing it in one of my databases and (1, 0) (true, false) and ('true', 'false') all work as expected. Make sure you have records that match your criteria as well.
If that doesn't work, do a desc on the table and post it. I'll try and figure out what's wrong.
|

03-21-2006, 01:41 PM
|
|
SEO Almost
|
|
Join Date: Sep 2004
Posts: 114
|
|
|
You're correct it is converted to tinyint. The problem is that the default value for bool is NULL and mysql doesn't consider NULL to be false.
cid varchar(10) YES NULL
active int(1) YES NULL
login_time datetime YES NULL
kicked tinyint(1) YES NULL
banned tinyint(1) YES NULL
listenonly int(1) YES NULL
audio varchar(30) YES NULL
request_audio tinyint(1) YES NULL
comments varchar(255) YES NULL
__________________
www.harddrivecaddy.com
|

03-21-2006, 01:44 PM
|
|
SEO Almost
|
|
Join Date: Sep 2004
Posts: 114
|
|
|
drop table users;
CREATE table users (
cid varchar(10),
active bool default 'false',
login_time DATETIME,
kicked bool default 'false',
banned bool default 'false',
listenonly bool default 'false',
audio varchar(30),
request_audio bool default 'false',
comments varchar(255)
);
__________________
www.harddrivecaddy.com
|

03-21-2006, 01:47 PM
|
|
SEO
|
|
Join Date: Sep 2005
Location: Fort Collins, Colorado
Posts: 446

|
|
|
Ah ha, I should have guessed. This has bitten me in the rear more than once.
So to solve this problem, make your boolean fields have a default value of 0 or false. This way they are always set.
It's one of those great CS concepts that Null != Null. You can only test to see if something IS NULL. So you could modify your query also:
select cid,login_time from users where (active = 1) AND (banned = 0 OR banned IS NULL) AND (kicked = 0 OR kicked IS NULL)
Pesonally I think just setting a default value is easier. If you need to update your current set of users you could do something like:
UPDATE users set kicked = 0 WHERE kicked IS NULL;
UPDATE users set banned = 0 WHERE banned IS NULL;
Hopefully that helps.
By the way did you know that x == x is a false statement because x could be NULL or NaN and it wouldn't be true any more. Ahh computer science.
|

03-21-2006, 05:58 PM
|
|
SEO Almost
|
|
Join Date: Sep 2004
Posts: 114
|
|
|
I just dropped the table and added default '0' to the table layout. Interestinly enough.. This is for an ajax application. I use xajax.
__________________
www.harddrivecaddy.com
|

03-21-2006, 09:36 PM
|
|
SEO
|
|
Join Date: Sep 2005
Location: Fort Collins, Colorado
Posts: 446

|
|
|
XAJAX? I don't think I'm familiar witht that term.
Looks like it's just another AJAX framework. Is that correct? What do you think about it? I did use SAJAX for a while, but I like having control over what's going on.
|
 |
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|