PDA

View Full Version : Query: & && or AND Help


Adrian Schneider
01-30-2005, 10:36 PM
$standingsfull=$DB_site->query("SELECT * FROM user WHERE wins!='0' & losses!='0' ORDER BY rating DESC");

Okay I have tried AND, & and &&, and neither work. The way it is now (with single &) it ignores the != on the right side of the &. With && it selects both of them (completely ignoring my !=, and with AND I get the same as &&. Anyone have any ideas?

cinq
01-30-2005, 11:20 PM
$standingsfull=$DB_site->query("SELECT * FROM user WHERE wins!=0 AND losses!=0 ORDER BY rating DESC");

should work.

But then your query logic seems odd.

Adrian Schneider
01-30-2005, 11:26 PM
For the standings, I don't want it to display people who havn't played any games, or there would be an extra thousand people in there inbetween the good/middle and the lower scored players.

cinq
01-30-2005, 11:37 PM
For the standings, I don't want it to display people who havn't played any games, or there would be an extra thousand people in there inbetween the good/middle and the lower scored players.

It's difficult to understand your explanation without more background info and possibly table structure. :)

Paul M
01-30-2005, 11:40 PM
For the standings, I don't want it to display people who havn't played any games, or there would be an extra thousand people in there inbetween the good/middle and the lower scored players.The you should be using OR, not AND - otherwise someone who has never won (or never lost) will not be displayed.

Personally, I would use this ;

DB_site->query("SELECT * FROM user WHERE wins>0 OR losses>0 ORDER BY rating DESC");

noppid
01-31-2005, 12:08 AM
He's right, I got lost in that logic too. It's OR.

filburt1
01-31-2005, 12:52 AM
& is bitwise "and" in most languages. For clarity in both PHP and SQL, I use the keyword "and" (and "or").

AnhTuanCool
01-31-2005, 01:59 AM
& is bitwise "and" in most languages. For clarity in both PHP and SQL, I use the keyword "and" (and "or").

That's right, imagine writting code like writting an essay :D.

Xenon
01-31-2005, 01:17 PM
i also use AND/OR in C++ as i defined makros there, so the & is just used for bitwise operations.

it's much easier to read the code quickly then :)