**SOLVED** SELECT * FROM users WHERE AND

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mikes1471
Forum Commoner
Posts: 88
Joined: Sat Jan 24, 2009 3:29 pm

**SOLVED** SELECT * FROM users WHERE AND

Post by mikes1471 »

Hi Everyone

I realise the header makes no sense in the format Ive written it but honestly at this stage Im unsure of the best way to call data from my database

Currently I display a list of user values on my webpage but for records that dont contain a value in 'Gender', theyre still being displayed, I dont want this, so thought I could SELECT * FROM users WHERE gender ="male" AND "female"

Will that work or is there a better way?
Last edited by mikes1471 on Wed Oct 14, 2009 9:06 pm, edited 1 time in total.
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: SELECT * FROM users WHERE AND

Post by Mirge »

Who is male AND female? :)
mikes1471
Forum Commoner
Posts: 88
Joined: Sat Jan 24, 2009 3:29 pm

Re: SELECT * FROM users WHERE AND

Post by mikes1471 »

Lol I want to select records for both males and females
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: SELECT * FROM users WHERE AND

Post by Griven »

... wouldn't that be all of them?
mikes1471
Forum Commoner
Posts: 88
Joined: Sat Jan 24, 2009 3:29 pm

Re: SELECT * FROM users WHERE AND

Post by mikes1471 »

No, I'm storing all data in one table, this includes image upload data recorded in the database which is simply a datestamp, filename and the location of the file on the webserver , in which case the gender isn't posted
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: SELECT * FROM users WHERE AND

Post by requinix »

1. You don't want rows where the gender is male and female, or want it where it's male or female.
2. There is no "X = A or B" shortcut. You have to spell it out all the way.
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: SELECT * FROM users WHERE AND

Post by Mirge »

SELECT * FROM users WHERE gender='male' OR gender='female';

Or... since those really are the only 2 options..

SELECT * FROM users WHERE LENGTH(gender) > 0;

etc... few different ways you could go at it.
mikes1471
Forum Commoner
Posts: 88
Joined: Sat Jan 24, 2009 3:29 pm

Re: SELECT * FROM users WHERE AND

Post by mikes1471 »

Excellent thankyou!!
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: **SOLVED** SELECT * FROM users WHERE AND

Post by Eran »

[sql]WHERE gender IS NOT NULL[/sql]
assuming your default state is a NULL value
Post Reply