SEO | Link Popularity | Search Engine Consulting | SEO Tutorial | SEO Tools | SEO Forum
Reply
 
Thread Tools Rating: Thread Rating: 7 votes, 5.00 average. Display Modes
  #1  
Old 03-20-2006, 07:03 PM
Atomical Atomical is offline
SEO Almost
 
Join Date: Sep 2004
Posts: 114 Atomical is on a distinguished road
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
Reply With Quote
  #2  
Old 03-21-2006, 06:19 AM
RyanSmith RyanSmith is offline
SEO
 
Join Date: Sep 2005
Location: Fort Collins, Colorado
Posts: 446 RyanSmith will become famous soon enoughRyanSmith will become famous soon enough
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.
__________________
AJAX Example Sites is now here! With a nice
AJAX Chat Application Tutorial
Reply With Quote
  #3  
Old 03-21-2006, 08:09 AM
Atomical Atomical is offline
SEO Almost
 
Join Date: Sep 2004
Posts: 114 Atomical is on a distinguished road
Yeah, it is a boolean. I'll try that when I get home.
__________________
www.harddrivecaddy.com
Reply With Quote
  #4  
Old 03-21-2006, 11:49 AM
Atomical Atomical is offline
SEO Almost
 
Join Date: Sep 2004
Posts: 114 Atomical is on a distinguished road
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
Reply With Quote
  #5  
Old 03-21-2006, 12:16 PM
RyanSmith RyanSmith is offline
SEO
 
Join Date: Sep 2005
Location: Fort Collins, Colorado
Posts: 446 RyanSmith will become famous soon enoughRyanSmith will become famous soon enough
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.
__________________
AJAX Example Sites is now here! With a nice
AJAX Chat Application Tutorial
Reply With Quote
  #6  
Old 03-21-2006, 12:41 PM
Atomical Atomical is offline
SEO Almost
 
Join Date: Sep 2004
Posts: 114 Atomical is on a distinguished road
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
Reply With Quote
  #7  
Old 03-21-2006, 12:44 PM
Atomical Atomical is offline
SEO Almost
 
Join Date: Sep 2004
Posts: 114 Atomical is on a distinguished road
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
Reply With Quote
  #8  
Old 03-21-2006, 12:47 PM
RyanSmith RyanSmith is offline
SEO
 
Join Date: Sep 2005
Location: Fort Collins, Colorado
Posts: 446 RyanSmith will become famous soon enoughRyanSmith will become famous soon enough
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.
__________________
AJAX Example Sites is now here! With a nice
AJAX Chat Application Tutorial
Reply With Quote
  #9  
Old 03-21-2006, 04:58 PM
Atomical Atomical is offline
SEO Almost
 
Join Date: Sep 2004
Posts: 114 Atomical is on a distinguished road
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
Reply With Quote
  #10  
Old 03-21-2006, 08:36 PM
RyanSmith RyanSmith is offline
SEO
 
Join Date: Sep 2005
Location: Fort Collins, Colorado
Posts: 446 RyanSmith will become famous soon enoughRyanSmith will become famous soon enough
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.
__________________
AJAX Example Sites is now here! With a nice
AJAX Chat Application Tutorial
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Login/Register
User Name
Password
Remember Me?

Forum Links
Forum Home
SEO Forum
Internet Marketing Forum
Web Design Forum
Web Hosting Forum
Programming Forum
SEO Chat

Quick Links
Forum Home
New Posts
Mark Forums Read
Open Buddy List
User Control Panel
Edit Avatar
Edit Profile
Edit Options
Miscellaneous
Subscribed Threads
My Profile

Search Forums

Advanced Search
All times are GMT -8. The time now is 03:39 AM.


Powered by: vBulletin Version 3.0.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.