Forum Moderators: coopster

Message Too Old, No Replies

is this possible?

2 'wheres' in mysql statement

         

surrealillusions

4:55 pm on May 15, 2008 (gmt 0)

10+ Year Member



Take this statemet (from my other post about echoing when empty etc..)

$data = mysql_query ("SELECT * FROM database WHERE animal='hamster' ORDER BY id DESC")

Can you add 2 where statements in there?

such as

$data = mysql_query ("SELECT * FROM database WHERE animal='hamster' WHERE animal='giraffe' ORDER BY id DESC")

Is that possible?

Staffa

5:07 pm on May 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$data = mysql_query ("SELECT * FROM database WHERE animal='hamster' WHERE animal='giraffe' ORDER BY id DESC")

You could do :

$data = mysql_query ("SELECT * FROM database WHERE animal='hamster' AND animal='giraffe' ORDER BY id DESC")

LifeinAsia

5:21 pm on May 15, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Um, unless there is such a beast as "hamstiraffe" or "giramster," I suggest the following instead:
SELECT *
FROM database
WHERE animal='hamster' OR animal='giraffe'
ORDER BY id DESC

[edited by: LifeinAsia at 5:21 pm (utc) on May 15, 2008]

surrealillusions

5:41 pm on May 15, 2008 (gmt 0)

10+ Year Member



thanks guys

the 'and' worked for what i need, but its nice to know that there is an 'or' option too.

What other options are there that can go in there?

:)

LifeinAsia

6:03 pm on May 15, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



NOT (as in "OR NOT" and "AND NOT")

chorny

8:12 pm on May 15, 2008 (gmt 0)

10+ Year Member



surrealillusions, read mysql documentation - you can't write program without knowing language.

surrealillusions

9:03 pm on May 15, 2008 (gmt 0)

10+ Year Member



I do read it, or at least try to read it, and php tutorials etc.. but sometimes i cant find the simple stuff..

:)